######################################################################
# BitchX format changes by Ankh
# liam@holoweb.net, ankh@sorcery.net

# installation: change the value of ANKHDIR below.
#
# colour use:
# I generally use dark brown text on a white background in a
# gnome terminal - you can also use a dark terminal with grey
# text.
#

# $Id: ankh.bx,v 1.39 2002/02/04 23:27:15 lee Exp $

######################################################################
# debugging suggestion:
#   put {{xx}} at the start of format_xx and you'll see when it's used!

########### Configuration: things you can easily change:

#### key bindings for sanity

bind ^B BACKWARD_CHARACTER
bind ^F FORWARD_CHARACTER
bind ^E END_OF_LINE
bind ^K ERASE_TO_END_OF_LINE
bind ^V QUOTE_CHARACTER
bind ^Wn NEXT_WINDOW

package Ankh
alias Ankh { return 1.39 }

# don't chop channel names:
set channel_name_width 0

# don't kick people off channels if they flood, or at least, not
# automatically.
set flood_protection off

# join channels I'm invited to by ChanServ -- use this only on
# a network where you trust ChanServ!
on invite "ChanServ *" {
    echo $raf(${fg.nick}ChanServ%n)--invited you to ${fg.channel}$1$n
    join $1
}

alias wji {
    window new name $0-
    cs invite $0
}

# change [hide] to [show] if you want to see NickServ kill messages --
# this only applies if you are umode +k, or are an IRC operator.
@ShowNickServKills = [hide] 

# myNet is the string at the end of most or all net servers,
# such as sorcery.net or dal.net;
# it's used to make LINKS output clearer.
@myNet = [sorcery.net]


# ANKHDIR is normally ~/.BitchX/ankh
# put ankh.bx in that directory
# add
# /load $HOME/.BitchX/ankh/ankh.bx
# to your $HOME/.bitchxrc
#
@ANKHDIR = [$HOME/.BitchX/ankh]

#### appearance
# nickWidth is the width allowed for the left-hand column
# if many people have nicks longer than nickWidth characters,
# you will need to increase the value
assign nickWidth -16

#### default colours if you have not loaded a theme
# the goal is to have very few colours on the screen, so that
# when colour _is_ used, it stands out more.
#
# note: these are not used everywhere yet, so changing them does
# not work well, I'm sorry.
#

# nicks of people speaking in channel, etc.:
@tvar.Nick = %W

# text when my nick ($N) is mentioned:
@tvar.myText = %y

# and when I say something:
@tvar.mySpeech = %y

# my nick when i speak or do an action:
@tvar.myNick = %Y

# channel names
@tvar.channelName = %c

# a nick when someone sends you a message, or [msg] when you send one:
@tvar.privmsg = %p

# same for a notice:
@tvar.notice = %p

# server messages, wallops, globops etc:
@tvar.server = %g

# nicks in dcc
@tvar.dcc = %r

# headings in help text
@tvar.Help = %c

# the word "error" in error messages
@tvar.Error = %R

# globals need emphasis!
@tvar.globals = %G

# timestamp colour (grey)
@tvar.timestamp = [37m]

# colours for /names and /sc:
@tvar.names_op = %c
@tvar.names_v = %r
@tvar.names_n = %n

# colour for URL grabs, and underlines
# colour must come before underlines
@tvar.url = [%b]

# hmm, need to change this
# @tvar.numerics = [%W�%n��]
# maybe tvar.colours.mYnick, etc.?

# Window Settings
# allow small windows:
set ALWAYS_SPLIT_BIGGEST OFF


#### End of configurtion section
######################################################################


########### Below this point you can still change it if you like, but
###########       it's harder

######################################################################

# utilities and internal variables

# for 75p3 or later:
alias p3set {
    if ([$V] >= [19990221]) {
	set $0-
    }
}

# for 75p2 or earlier: (75p2 was recalled, so this is really 75p1)
alias p2set {
    if ([$V] < [19990221]) {
	set $0-
    }
}

alias p2fset {
    if ([$V] < [19990221]) {
	fset $0-
    }
}

alias p3fset {
    if ([$V] >= [19990221]) {
	fset $0-
    }
}

@ padWidth = 0 - nickWidth

# note the trailing space on the ^set line below!
alias ankh.setline {
    ^set CONTINUED_LINE $([$nickWidth])$(0) 
    ^assign ankh.vline $0
}

alias doPCfont {
    if ([$usePCfont] == [no]) {
	ankh.setline |
	@ G = [***]
	^set show_numerics_str ***
    } {
	ankh.setline �
	@ G = [$cparse(��%W�%n)]
	^set show_numerics_str $G
    }
}
doPCfont

# colour names
@ aicolour.black = 30
@ aicolour.red = 31
@ aicolour.green = 32
@ aicolour.yellow = 33
@ aicolour.blue = 34
@ aicolour.magenta = 35
@ aicolour.cyan = 36
@ aicolour.white = 37
@ aicolour.default = 39
# ESC [ Ps m
#     Character Attributes (SGR)
#     Ps = 0 : Normal (default)
#     Ps = 1 / 22 : On / Off Bold (bright fg)
#     Ps = 4 / 24 : On / Off Underline
#     Ps = 5 / 25 : On / Off Blink (bright bg)
#     Ps = 7 / 27 : On / Off Inverse
#     Ps = 30 / 40 : fg / bg Black
#     Ps = 31 / 41 : fg / bg Red
#     Ps = 32 / 42 : fg / bg Green
#     Ps = 33 / 43 : fg / bg Yellow
#     Ps = 34 / 44 : fg / bg Blue
#     Ps = 35 / 45 : fg / bg Magenta
#     Ps = 36 / 46 : fg / bg Cyan
#     Ps = 37 / 47 : fg / bg White
#     Ps = 39 / 49 : fg / bg Default

# FSET FORMAT_TIMER $G $[-5]0 $[-10]1 $[-6]2 $3-

# internal alias for setting a colour
alias setColour {
    if ([$left(1, $0)] == [%]) {
	return $before(x $cparse($0x));
    } else {
	return $0
    }
}

# aioneColourTest is internal, 
# give it name, e.g. green
alias aioneColourTest {
    @ :bg

    if ([$0] == []) {
	@ bg = []
    } {
	@ bg = aicolour[$0]
	@ bg += 10
	@ bg #= [\;]
    }
    @ :cname
    @ :s2
    @ :str = []
    foreach aicolour cname {
	@ s2 = [ \[${bg}] ## tolower($aicolour[$cname]) ## [m] ## tolower($cname) ## nc
	@ str #= s2
    }
    @ :fg = [\[] ## tolower($aicolour[$0]) ## [m]
    echo $raf(${fg}$0%n:) $cparse("$str")
    # bold
    @ :str = []
    foreach aicolour cname {
	@ s2 = [ \[1\;${bg}] ## tolower($aicolour[$cname]) ## [m] ## tolower($cname) ## nc
	@ str #= s2
    }
    echo $raf(:) $cparse("$str")

}

# alias to show colours
alias colourtest {
    hline -left "colour test"
    @ cn
    foreach aicolour cn {
	aioneColourTest $cn
    }
    aioneColourTest default
    hline
}

# untested code:
alias cktime {
    if (ankh.wantstamp == 1) {
	@ankh.wantstamp = 0;
	^local hh $strftime(%H)
	^local mm $strftime(%M)
	^local mdiv2
	if (ankh.ts == 0) {
	    @ mdiv2 = 999
	} {
	    @ mdiv2 = mm / ankh.ts
	}
	if ($ankh.ts == 0 || [${hh}$mdiv2] != [$ankh.lastts[$0]]) {
	    @ leftPad -= 5
	    @ ankh.lastts[$0] = [${hh}$mdiv2]
	    ^on window -*
	    echo ${fg.timestamp}${hh}:${mm}${nc}$([$leftPad] )$t
	    ^on -window * {cktime $0-}
	}
    }
}

# e.g. $raf(-$(1)-) produces "         -percy-"
# This is more complex than it looks because we need to take into
# account colour codes.
alias raf {
    ^local t $cparse("$*" cparse)
    ^local leftPad ${[$padWidth]-[$printlen($stripansicodes($t))]}
    if (ankh.ts >= 0) {
	^local hh $strftime(%H)
	^local mm $strftime(%M)
	^local mdiv2
	if (ankh.ts == 0) {
	    @ mdiv2 = 999
	    @ ankh.lastts = 0
	} {
	    @ mdiv2 = mm / ankh.ts
	}
	if ($ankh.ts == 0 || [${hh}$mdiv2] != [$ankh.lastts]) {
	    if (leftPad > 5) {
		@ leftPad -= 5
		@ ankh.lastts = [${hh}$mdiv2]
		return ${fg.timestamp}${hh}:${mm}${nc}$([$leftPad] )$t
	    } elsif (leftpad > 3) {
		@ leftPad -= 3
		@ ankh.lastts = [${hh}$mdiv2]
		return ${fg.timestamp}:${mm}${nc}$([$leftPad] )$t
	    } elsif (leftpad > 2) {
		@ leftPad -= 2
		@ ankh.lastts = [${hh}$mdiv2]
		return ${fg.timestamp}${mm}${nc}$([$leftPad] )$t
	    }
	}
    }
    if (leftpad <= 0) {
	return $t
    } else {
	return $([$leftPad] )$t
    }
}

# raf no timestamp
# needs a short name because it's expanded for every input prompt!!!
alias rnt {
    ^local t $cparse("$*" cparse)
    ^local lPad ${[$padWidth]-[$printlen($stripansicodes($t))]}
    return $([$lPad] )$t
}

# laf is to left-justify something in a given field
# actually if $0 is -ve it works a but like $raf, except that $raf
# handles colour properly and $laf() doesn't.
# This version is dramatically faster than the one that came with ircII,
# which loops through looking at each character.
alias laf {
    return $([$0]1-)
}

# This is used to simplify links output.
alias unnet {
    return $sar(/.${myNet}//$0-)
}

# e4 is an alias to make some blank lines on the screen.
# if you go away for a minute, do e4 and then you'll easily
# see where you left off.
alias e4 {
    xecho -current
    xecho -current
    xecho -current
    xecho -current
}

# use $nc to turn colours off
@nc = [$setColour(%n)]

# hline draws a line across the screen
# /hline gone for coffee
# will leave a visible marker.
# hline [-left "leftstuff"] [-right rightstuff]
alias hline {
    ^local segment �
    if (usePCfont == [no]) {
	@ segment = [_]
    }
    @ :tmp = geom()
    @ :width = word(0 $tmp) + NickWidth - 2
    @ :lb = []
    @ :rb = [$0-]
    if ([$0] == [-left]) {
	@ lb = [ $1]
	@ rb = [$2-]
	if ([$2] == [-right]) {
	    @ rb = [$3-]
	    @ segment = []
	}
    } {
	if ([$0] == [-right]) {
	    @ rb = [$1-]
	    @ segment = []
	}
    }
    if (rb != []) {
	@ rb = [$cparse("$rb") ]
    } {
	@ :i = 0
	# $pad() is broken in some versions of BX..
	for (@ i = 1, i < width, @ i++) {
	    @ rb #= [${segment}]
	}
    }
    xecho -current $([$(nickWidth) ${segment}]lb)* $rb
}

# chops [chan] message
# send a notice to channel ops
alias chops {
    if ([$left(1, $0)] == [#]) {
	quote notice @$0 :[ops/$0] $1-
	xecho -current $raf(->${fg.channelName}@$0%n)- [ops/$0] $1-
    } else {
	quote notice @$C :[ops/$C] $0-
	xecho -current $raf(->%${fg.channelName}$C%n)- [ops/$C] $0-
    }
}

######################################################################
### Themes

@cdesc.Nick = [Nicknames when people speak in a channel or elsewhere]
@cdesc.myText = [Text typed by other people, when it contains my nick]
@cdesc.mySpeech = [Text I type in channels]
@cdesc.myNick = [My Nick when I speak ina channel]
@cdesc.channelName = [Name of a channel in a prompt, topic, mode, etc.]
@cdesc.privmsg = [Text of messages sent, and nicks of messages sent]
@cdesc.notice = [Text of notices sent, and nicks of messages sent]
@cdesc.dcc = [nicks in DCC send/get/request etc]
@cdesc.server = [Sever messages and server names]
@cdesc.Help = [Headings in help text]
@cdesc.Error = [Highlighting in error messages (e.g. the word Error)]
@cdesc.Globals = [Highlighting for WALLOPS and Globals]
@cdesc.url = [URLs seen in a channel are copied in this colour]
@cdesc.timestamp = [Highlighting for timestamp (/aconf timestamp)]
@cdesc.names_op = [colour of op nicks in a /names or /sc]
@cdesc.names_v = [colour of voiced (+v) nicks) in a /names or /sc]
@cdesc.names_n = [colour of normal nicks in a /names or /sc]

alias showTheme {
    hline $tvar[name]
    ^local cname
    foreach cdesc cname
    {
	echo $raf(${fg.Help}$tolower($cname)%n): $cdesc[$cname] [$fg[$cname]sample${nc}]
    }
    hline
}

# changeTheme name value -- sets the given name
# e.g. /themeSet myNick %Y
alias themeSet {
    if ([$0] == []) {
	echo
	hline ${fg.Help}themeSet%n: /themeSet variable value
	onehelp ${fg.Help}themeSet${nc} the variables are listed by /showtheme\; an example might be /themeSet myNick \%Y
	hline
	return
    }
    if ([$cdesc[$0]] == []) {
	echo $raf(${fg.error}error%n): you must give a theme variable name\; use /showtheme for a list.  Example: /themeSet Notice \%g
	return
    }
    if ([$1] == []) {
	echo $raf(${fg.error}caution%n): you are setting $1 to the empty string.  Previously it was "$tvar.$1"\; you probably want \%w instead, for the default foreground colour.
	echo $raf(${fg.Help}$tolower($0)%n): $cdesc[$0] [$fg[$0]previous value${nc}]
    }
    @ tvar[$0] = [$1]
    @ fg[$0] = [$setColour($1)]
    echo $raf(${fg.Help}$tolower($0)%n): $cdesc[$0] [$fg[$0]new value${nc}]
}

alias loadTheme {
    ^local fname $ANKHDIR/themes/$0
    ^local themename $0

    if ([$0] == [save]) {
	saveTheme
	return
    }

    if ([$0] == []) {
	echo $raf(${fg.error}error%n): you must give a theme name, without the .bx suffix, e.g. /aconf theme plain. /aconf theme -list gives a list of themes and /aconf theme save will save the current theme.
	return
    }

    if ([$fexist($ANKHDIR/themes/plain.bx)] == [-1]) {
	echo $raf(${fg.error}mishap%n): Your ankh.bx script is not installed properly:
	echo $raf(${fg.error}mishap%n): The file $ANKHDIR/themes/plain.bx isn't there, of you don't have permission to read it... check ANKHDIR is set properly in the script.
	# set defaults in case this is the first time
	^local cname
	foreach tvar cname
	{
	    @ fg[$cname] = [$setColour($tvar[$cname])]
	}
	return
    }

    if ([$0] == [-list]) {
	hline Themes available:
	exec -window \
	    cd $ANKHDIR/themes \; \
	    for i in *.bx\; \
	    do \
	        head -1 \$i\; \
	    done\; \
	    echo
	return
    }

    if ([$fexist(${fname}.bx)] != [1]) {
	if ([$1] == [silent]) {
	    return
	}

	echo $raf(${fg.error}error%n): Cannot find theme $fname [tried $ANKHDIR/themes/${fname}.bx]
	return
    }

    # the theme can override its name if it wants:
    @ tvar.name = [$themename]

    load ${fname}.bx

    ^local cname
    foreach tvar cname
    {
	@ fg[$cname] = [$setColour($tvar[$cname])]
    }
    if ([$1] != [silent]) {
	hline loaded ankh.bx theme: $fname
    }
}

# saveTheme saves the current settings to the "default" theme
alias saveTheme {
    ^local fname $ANKHDIR/themes/default.bx

    if ([$fexist($ANKHDIR/themes/plain.bx)] == [-1]) {
	echo $raf(${fg.error}mishap%n): Your ankh.bx script is not installed properly:
	echo $raf(${fg.error}mishap%n): The file $ANKHDIR/themes/plain.bx isn't there, of you don't have permission to read it... check ANKHDIR is set properly in the script.
    }

    @ unlink($fname)

    ^local fd
    @ fd = [$open($fname W)]
    if ([$fd] == [-1]) {
	echo $raf(${fg.error}mishap%n): Could not save current theme to $fname (make sure the directory $ANKHOME/themes is there and that you have permission to write to it; if not, change the definition of ANKHOME in the ankh.bx script.
	return
    }

    @ write($fd # default -- $tvar[name])

    ^local cname
    foreach tvar cname
    {
	@ write($fd # $cname -- $cdesc[$cname])
	@ :colour = [$tvar[$cname]]

	if (left(1, $colour) == [$chr(27)]) {
	    echo found esc in $cname
	    # bug: have to leave out the trailing [ for some reason
	    @ write($fd @tvar.$cname = [\$chr(27)$mid(1 99 $tvar[$cname]))
	} else {
	    echo $cname has left of $left(1, $colour)
	    @ write($fd @tvar.$cname = [$tvar[$cname]])
	}
	@ write($fd)
    }

    if ([$close($fd)] == [-1]) {
	echo
	echo $raf(${fg.error}mishap%n): error on closing $ANKHDIR/themes/default -- check the disk is not full!
	exec df $ANKHDIR/themes
	hline
	return
    }

    hline ${fg.Help}Saved current theme, $tvar[name]%n
}


######################################################################
# Useful window aliases

# wk -- kill a window
alias wk /window kill

# wj #chan -- join a channel in a new window
alias wj {
    window new name $0-
    join $0
}

# wp -- kill current window and part channel
# it would be nice if you could say /wp #chan, and have the
# corresponding window closed, but you can't right now.
alias wp {
    part * $0-
    window kill
}
alias wkp {
    part * $0-
    window kill
}

alias wk {
    window kill
}


# qw - query window for given nick
alias qw {
    window new name $0 query $0-
}

# qk -- query kill
alias qk {
    query
    window kill
}


######################################################################
# help on this script
alias oneHelp {
    echo $raf(${fg.Help}$0%n): $1-
}

@ahelp.aconf = [/aconf (runtime configuration options)]
@ahelp.chops = [/chops #chan message for ops to see in a notice; if you leave off #chan, the current channel will be used.]
@ahelp.wj = [/wj #chan Join the named channel in a new window]
@ahelp.wk = [/wk /window kill -- close window without parting any channels]
@ahelp.wkp = [/wkp reason parts the current channel (*) with reason (if given), and then closes the window]
@ahelp.wp = [/wp reason (same as wkp)]
@ahelp.qw = [/qw nick open a new window and make it a query with with nick]
@ahelp.qk = [/wk end the query and close the window, after /qk]
@ahelp.hline = [/hline pretty stuff draws a horizontal line across the screen, or, if you give any arguments, draws those.  You can use colours (e.g. %g for green) in the arguments; see /ahelp colours]
@ahelp.e4 = [/e4 leaves four blank lines]
@ahelp.info = [Ankh.bx was written by Liam Quin (Ankh on irc.sorcery.net, ankle5 on DALnet) with help from String and others.  The goal of ankh.bx is to make BitchX be more restrained in its use of colour and layout, according to typographic design principles.]
@ahelp.ankh = [Ankh wrote this script (see /ahelp info); he is usually barefooted, and can be found as Ankh on irc.sorcery.net, or ankh@sorcery.net, http://www.holoweb.net/~liam/    Thanks also to String for many helpful suggestions.]
@ahelp.aload = [/aload reloads this script (${ANKHDIR}/ankh.bx)]
@ahelp.asave = [/asave saves your /aconf settings]

@ahelp.globops = [/globops message to all opers on the network]
@ahelp.locops =  [/locops message to all opers on this server]
@ahelp.id =  [/id prompts for pass and sends to nickserv. The password is remembered for the rest of the current session - use /id - to force /id to prompt again.]
@ahelp.matchkill =  [does /os autokill and matches the nick!user@host you give it against each entry, shows any that would ban the given user]
@ahelp.clonewho =  [does a /who on the last clone warning from SorceryNet operserv]
@ahelp.clonekill =  [does a /whokill on the last clones operserv warned about, with optional reason]
@ahelp.cloneakill =  [adds an autokill for 1 hour, takes optional reason]
@ahelp.clonetrigger =  [increases the trigger for the host OperServ warned about]
@ahelp.clonewarn =  [sends a warning notice to whoever OperServ last warned about, please do not run clones on this network]

@ahelp.loadTheme = [/loadTheme name loads a colour scheme for the ankh.bx script, e.g. /loadTheme plain]
@ahelp.saveTheme = [/saveTheme saves your current theme, overwriting the default theme, so you can edit it]

alias ahelp {
    if ([$0]==[]) {
	e4
	hline ${fg.Help}Help Index for Ankh.bx%n
	echo $raf(${fg.help}Window Commands%n): wj wk wkp wp qw qk
	echo $raf(${fg.help}Channels%n): chops
	echo $raf(${fg.help}Services%n): id ns cs ms os is
	echo $raf(${fg.help}irc operators%n): globops helpops
	echo $raf(${fg.help}Configuration%n): aconf aload
	echo $raf(${fg.help}Formatting%n): hline e4
	echo $raf(${fg.help}People%n): info
	echo $raf(${fg.help}Operator%n): matchkill clonewho clonekill cloneakill clonetrigger clonewarn
    } else {
	if ([$(ahelp.$0)]==[]) {
	    echo $raf(${fg.error}oops%n): no help for $0.  Use /ahelp for the index.
	    echo
	} else {
	    hline ${fg.Help}Ankh.bx: Help for $0%n
	    oneHelp $0 $(ahelp.$0)
	    if ([$1]!=[]) {
		ahelp $1-
	    }
	}
    }
}

######################################################################

# formats -- the original value is given with #@

###################################
## friends and enemies
#

# I don't use this myself -- it's mainly an EFnet feature.
# on DALnet ,sorcerynet, or other services-based nets, you use
# chanserv and nickserv to manage auto-opping and auto-banning,
# so the irc client doesn't need to.

# (on Undernet, use Uworld, X and W)

# FSET FORMAT_FRIEND_JOIN $G %R$1 %K[%c$2%K]%n has joined $3
# FSET FORMAT_USERLIST $[16]0 $[10]1 $[-10]2   $[-25]3 $[10]4
# FSET FORMAT_USERLIST_FOOTER There are $1 users on the userlist
# FSET FORMAT_USERLIST_HEADER level            nick       password     host                      channels
# FSET FORMAT_USERS_HEADER %K[ %WC%nhannel  %K][ %WN%wickname %K][%n %Wu%wser@host                       %K][%n %Wl%wevel         %K]

# FSET FORMAT_USERS_SHIT %K[%n$[10]1%K]%K[%n%C$4%B$[9]2%K]%K[%n%r$[33]3%K]%K[%n$[-16]0%K]
# p3set FORMAT_USERS_SHIT %K[%n%C$4%B$[9]2%K]%K[%n%r$[41]3%K]%K[%n$[-16]0%K]

#@ p3set FORMAT_USERS_TITLE $G Channel userlist for %W$1%n at ($0):
p3set FORMAT_USERS_TITLE $raf(${fg.channel}$1%n): Channel userlist at $0

# FSET FORMAT_USERS_USER %K[%n$[10]1%K]%K[%n%C$4%B$[9]2%K]%K[%n%B$[33]3%K]%K[%n$0%K]
#@ FSET FORMAT_USERS %K[%n$[10]1%K]%K[%n%C$4%B$[9]2%K]%K[%n$[33]3%K] %K[%n$0%K]
FSET FORMAT_USERS %K[%n$[10]1%K]%K[%n%C$4%B$[9]2%K]%K[%n$[33]3%K] %K[%n$0%K]
# p1set -FORMAT_USERS_BOT

# exempt bans
# p3set -FORMAT_EBANS_FOOTER
# p3set FORMAT_EBANS $[2]0 $[10]1 $[10]3 $[-5]numdiff($time() $4)  $2
# p3set FORMAT_EBANS_HEADER #  Channel    SetBy        Sec  ExemptBan

##################################
# private functions

# showText is called to show text in a channel.
# if it mentions your nick, it comes out in bright yellow.
alias showText {
    if ([$match(*$tolower($N)* $0-)]<=[0]) {
	return $0-
    } {
	return ${fg.myText}$0-
    }
}

###################################
## bitchx configuration, running, etc
# FSET FORMAT_CSET %r$[-14]1 %R$[-20.]0   %w$2-

###################################
## Actions and messages and notices
##
## Actions
#@ FSET FORMAT_ACTION %K� %W$1 %n$4-
# this is when someone does an action in a private msg, as in
# /describe panasync this is what i do
# i.e. a ctcp action to a nick rather than a channel
# 1 = their nick 2=their hostmask 3=my nick (?) 4- = message
FSET FORMAT_ACTION $raf(*${fg.privmsg}$1%n) ${fg.privmsg}<-%n %n$4-

#@ FSET FORMAT_ACTION_AR %K� %Y$1 %n$4-
# the _AR formats are for auto replies
# e.g. where someone else says something starting with your nick
FSET FORMAT_ACTION_AR $raf(*${fg.privmsg}$1%n) ${fg.privmsg}<-%n %n$4-

#@FSET FORMAT_ACTION_CHANNEL %K� %Y$1/$3 %n$4-
# this is when someone other than you does an action
FSET FORMAT_ACTION_CHANNEL $raf(*${fg.nick}$1%n)${ankh.vline} $showText($4-)%n

#@ FSET FORMAT_ACTION_OTHER %K* %n>%c$1 %n$3-
# someone did an action but not in the current channel
p2FSET FORMAT_ACTION_OTHER $raf(*${fg.nick}$1%n): $showText($3-)%n
p3FSET FORMAT_ACTION_OTHER $raf(*${fg.nick}$1%n): ${fg.channelName}$3%n $showText($4-)%n

#@ FSET FORMAT_ACTION_OTHER_AR %K* %y>%c$1 %n$3-
FSET FORMAT_ACTION_OTHER_AR $raf(*${fg.nick}$1%n): $showText($3-)%n

# FSET FORMAT_ACTION_USER %K* %n>%c$1 %n$3-
# FSET FORMAT_ACTION_USER_AR %K* %y>%c$1 %n$3-
# the _AR formats are for auto replies

#@ FSET FORMAT_SEND_ACTION %K� %W$1 %n$3-
# SEND_ACTION is when you use /me in a channel
FSET FORMAT_SEND_ACTION $raf(*${fg.myNick}$1%n)  %n${fg.mySpeech}$3-%n

# FSET FORMAT_SEND_ACTION_OTHER %K� %n-> %W$1%n/%c$2 %n$3-
# this is when you use /qme or /d
FSET FORMAT_SEND_ACTION_OTHER $raf(*${fg.privmsg}$1%n) [->${fg.privmsg}$2%n] $3-

# FSET FORMAT_SEND_NOTICE %K[%rnotice%K(%R$1%K)] %n$3-
FSET FORMAT_SEND_NOTICE $addwin(notice $1)$raf(->-${fg.notice}$1%n)- $3-

# addwin function nick
# add a user to a window if they are not already on the list.
# TODO see if they are on any list anywhere, and remove them if they are
# TODO keep only the last 20 or so nicks in the list??
alias addwin {
    if ([$match($1 $winnicklist())] == [0]) {
	/^window add $1
    }
}



###################################
## talking: messages, ctcp, notices
# FSET FORMAT_ENCRYPTED_NOTICE %K-%Y$1%K(%p$2%K)-%n $3-
# FSET FORMAT_ENCRYPTED_PRIVMSG %K[%Y$1%K(%p$2%K)]%n $3-

#@ FSET FORMAT_SEND_PUBLIC %P<%n$2%P>%n $3-
# SEND_PUBLIC is when you speak in a channel
# $1 = channel $2 = nick $3- = message
FSET FORMAT_SEND_PUBLIC $raf(${fg.myNick}$2%n): ${fg.mySpeech}$3-%n

#@ FSET FORMAT_SEND_PUBLIC_OTHER %p<%n$2%K:%n$1%p>%n $3-
# this is when you speak on a channel that's not the
# current one, e.g. with /msg #channel stuff
FSET FORMAT_SEND_PUBLIC_OTHER $raf(${fg.myNick}$2%n): ${fg.channelName}$1%n ${fg.mySpeech}$3-%n

#@ FSET FORMAT_SEND_MSG %K[%rmsg%K(%R$1%K)] %n$3-
#: SEND_MSG: used when you send a private message
#: arguments: 1=channel name; 2=your nick; 3-=the message
FSET FORMAT_SEND_MSG $raf(->${fg.privmsg}$1%n)  ${fg.privmsg}$3-%n

@ someone sends you a message:
#@ FSET FORMAT_MSG %K[%P$1%K(%p$2%K)]%n $3-
FSET FORMAT_MSG $raf(${fg.privmsg}$1%n)${fg.privmsg}: [msg]%n $3-

#@ FSET FORMAT_PUBLIC %B<%n$1%B>%n $3-
# PUBLIC is when someone else speaks in a channel you are on, and
# the channel is bound to the current window
FSET FORMAT_PUBLIC $raf(${fg.nick}$1%n): $showText($3-)%n

# FSET FORMAT_PUBLIC_AR %B<%Y$1%B>%n $3-
# the _AR formats are for auto replies
FSET FORMAT_PUBLIC_AR $raf(${fg.nick}$1%n): $showText($3-)%n

#@ FSET FORMAT_PUBLIC_MSG %b(%n$1%K/%n$3%b)%n $4-
# e.g. someone sends a message to a channel when they are not on the channel
# this will also happen if somene spekas after you have joined a
# channel but before BitchX has received the names list (i.e. synced)
FSET FORMAT_PUBLIC_MSG  $raf(${fg.nick}$1%n)  ${fg.channelName}$3%n $showText($4-)%n

# FSET FORMAT_PUBLIC_MSG_AR %b(%Y$1%K/%Y$3%b)%n $4-
# the _AR formats are for auto replies
FSET FORMAT_PUBLIC_MSG_AR  $raf(${fg.nick}$1%n)  ${fg.channelName}$3%n $showText($4-)%n

# FSET FORMAT_PUBLIC_NOTICE %K-%P$1%K:%p$3%K-%n $4-
# someone sent a notice to a channel
FSET FORMAT_PUBLIC_NOTICE $raf(-${fg.notice}$1%n)- ${fg.channelName}$3%n $4-

# FSET FORMAT_PUBLIC_NOTICE_AR %K-%G$1%K:%g$3%K-%n $4-
# the _AR formats are for auto replies
FSET FORMAT_PUBLIC_NOTICE_AR $raf(-${fg.notice}$1%n)->${fg.channelName}$3%n $showText($4-)%n

#@ FSET FORMAT_PUBLIC_OTHER %b<%n$1%K:%n$2%b>%n $3-
# this is when someone speaks on a channel bound to the current
# window, but not the current channel
FSET FORMAT_PUBLIC_OTHER $raf(${fg.nick}$1%n): ${fg.channelName}$2%n $showText($3-)%n

# FSET FORMAT_PUBLIC_OTHER_AR %b<%y$1%K:%n$2%b>%n $3-
FSET FORMAT_PUBLIC_OTHER_AR $raf(${fg.nick}$1%n): ${fg.channelName}$2%n $showText($3-)%n

#@ FSET FORMAT_NOTICE %K-%P$1%K(%p$2%K)-%n $3-
FSET FORMAT_NOTICE $raf(-${fg.notice}$1%n)- $showText($3-)%n


###################################
## CTCP
#@ FSET FORMAT_CTCP %K>%n>%W> %G$1 %K[%g$2%K]%g requested $4- from $3
FSET FORMAT_CTCP $raf(${fg.nick}$1%n)<-${fg.ctcp}ctcp%n from ${fg.nick}$3%n: $4-

# FSET FORMAT_CTCP_CLOAK %K>%n>%W> %C$1 %K[%c$2%K]%c requested $4- from $3
FSET FORMAT_CTCP_CLOAK CLOAK %K>%n>%W> %C$1 %K[%c$2%K]%c requested $4- from $3

# FSET FORMAT_CTCP_CLOAK_FUNC %K>%n>%W> %C$1 %K[%c$2%K]%c requested $4- from $3
FSET FORMAT_CTCP_CLOAK_FUNC CLOAK_FUNC %K>%n>%W> %C$1 %K[%c$2%K]%c requested $4- from $3

# FSET FORMAT_CTCP_CLOAK_FUNC_USER %K>%n>%W> %C$1 %K[%c$2%K]%c requested $4- from you
FSET FORMAT_CTCP_CLOAK_FUNC_USER CLOAK_FUNC_USER %K>%n>%W> %C$1 %K[%c$2%K]%c requested $4- from you

# FSET FORMAT_CTCP_CLOAK_UNKNOWN %K>%n>%W> %C$1 %K[%c$2%K]%c requested unknown ctcp $4- from $3
# FSET FORMAT_CTCP_CLOAK_UNKNOWN_USER %K>%n>%W> %C$1 %K[%c$2%K]%c requested unknown ctcp $4- from $3
# FSET FORMAT_CTCP_CLOAK_USER %K>%n>%W> %C$1 %K[%c$2%K]%c requested $4- from you
# FSET FORMAT_CTCP_FUNC %K>%n>%W> %G$1 %K[%g$2%K]%g requested $4- from $3
FSET FORMAT_CTCP_FUNC $raf($1)--CTCP $4 from $3 [$2]
# FSET FORMAT_CTCP_FUNC_USER %K>%n>%W> %G$1 %K[%g$2%K]%g requested $4- from you

#@ FSET FORMAT_CTCP_REPLY $G %nCTCP %W$3 %nreply from %n$1: $4-
FSET FORMAT_CTCP_REPLY $raf(${fg.nick}$1%n)<-${fg.ctcp}ctcp%n reply from ${fg.nick}$1%n: $3-

# FSET FORMAT_CTCP_UNKNOWN %K>%n>%W> %G$1 %K[%g$2%K]%g requested unknown ctcp $4- from $3
# FSET FORMAT_CTCP_UNKNOWN_USER %K>%n>%W> %G$1 %K[%g$2%K]%g requested unknown ctcp $4- from %g$3
#@ FSET FORMAT_CTCP_USER %K>%n>%W> %G$1 %K[%g$2%K]%g requested $4- from you
FSET FORMAT_CTCP_USER $raf(${fg.nick}$1%n)<-${fg.ctcp}ctcp%n $4-

#@ FSET FORMAT_SEND_CTCP %K[%rctcp%K(%R$1%K)] %n$2
FSET FORMAT_SEND_CTCP $raf(${fg.nick}$1%n)$cparse(->)%n${fg.ctcp}ctcp%n send ${fg.nick}$1%n: $2-

###################################
## file transfer and DCC
# FSET -FORMAT_DCC
#@ FSET FORMAT_DCC_CHAT %K[%G$1%K(%gdcc%K)] %n$3-
FSET FORMAT_DCC_CHAT $raf(=${fg.dcc}$1%n)= DCC $3-

#@ FSET FORMAT_DCC_CONNECT $G %RDCC%n $1 with %W$2%K[%c$4:$5%K]%n established
FSET FORMAT_DCC_CONNECT $raf(=${fg.dcc}$2%n)= DCC $1 established: $4:$5

#@ FSET FORMAT_DCC_ERROR $G %RDCC%n lost %w$1%w %rto $2 %K[%w$3-%K]
FSET FORMAT_DCC_ERROR $raf(=${fg.dcc}$2%n)= DCC ${fg.Error}lost%n $1: $3-

#@ FSET FORMAT_DCC_LOST $G %RDCC%n %W$1%n:%g$2%n %K[%C$3%K]%n $4 $5 completed in $6 secs %K(%W$7 $8/sec%K)
# this is shown when a DCC completes, despite the name
FSET FORMAT_DCC_LOST $raf(=${fg.dcc}$5)= $1 $2 ($3) completed in $6 secs ($7 $8/sec)

#@ FSET FORMAT_SEND_DCC_CHAT %K[%rdcc%K(%R$1%K)] %n$2-
FSET FORMAT_SEND_DCC_CHAT $raf(->${fg.dcc}$2%n)= $0 DCC $1 ${fg.dcc}$2%n $3-


#@ FSET FORMAT_DCC_REQUEST $G %RDCC%n $1 %K(%n$2%K)%n request from %W$3%K[%c$4 [$5:$6]%K]%n $8 $7
# $1 - the request type (GET< CHAT, etc.)
# $2 - "now" (I'm not sure what that is
# $3 - remote nick
# $4 - remote hostmask
# $5 remote IP
# $6 remote port
# $7, $8 -- I don't know
FSET FORMAT_DCC_REQUEST $raf(=${fg.dcc}$3%n)= DCC $1 ($2) request ($4) $7-

###################################
## irc operator formats
## See also the section at the end of this script with ON commands
## that traps various server messages.

#@ FSET FORMAT_381 %K>%n>%W> You are now a %GIRC%n whore
# args are: time, server, message
FSET FORMAT_381 $raf(${fg.server}$unnet($1)%n): $2-

# RemoveStar - return its argument, or, if given *, return my current nick:
alias RemoveStar {
    if ([$0] == [*]) {
	return [$N]
    } else {
	return [$0]
    }
}
# FSET FORMAT_BWALL [%GBX-Wall%n/%W$1:$2%n] $4-
# this is used by the WALL command to channel ops
# $1 = channel, $2 = nick, $3 = mask of sender (* for me) $4- = message
FSET FORMAT_BWALL $raf(${fg.nick}$RemoveStar($2)%n): ${fg.channelName}$1 (ops)%n: $4-

#@ FSET FORMAT_KILL %K>%n>%W> %RYou have been killed by $1 for $2-
FSET FORMAT_KILL $raf(${fg.Error}KILLED!%n) You have been killed by ${fg.nick}$1%n: $2-

#@ FSET FORMAT_OPER %C$1 %K[%c$2%K]%n )s now %Wan%w %GIRC%n operator
FSET FORMAT_OPER $raf(${fg.nick}$1%n)  [$2] is now an IRC operator

# FSET FORMAT_OV [41m%S %>[1;30m[[1;32mOper[1;37mView[1;30;41m] 

###################################
## Scripting formats
# FSET FORMAT_ALIAS Alias $[20.]0 $1-
# FSET FORMAT_ASSIGN Assign $[20.]0 $1-
# FSET FORMAT_HOOK $0-

###################################
## Other formats
# FSET FORMAT_AWAY is away: ($3-) $1 $2
#@ FSET FORMAT_BACK is back from the dead. Gone $1 hrs $2 min $3 secs
FSET FORMAT_BACK is back.  Gone $1 hrs $2 min $3 secs

# FSET FORMAT_BITCH %RBitch Mode Activated%n $1 $4 $5 on $3
# p3set FORMAT_LASTLOG $strftime($0 %H:%M) $1-


###################################
## Channel Operator formats
# FSET FORMAT_BANS $[2]0 $[10]1 $[10]3 $[-5]numdiff($time() $4)  $2
# FSET FORMAT_BANS_HEADER #  Channel    SetBy        Sec  Ban
# p3set -FORMAT_BANS_FOOTER

# channel bans
# FSET BANS %W$[-2]0%K:%n $[26]2 %K(%c$[20]3%K:%c$[24]4-%K)
# FSET BANS_FOOTER %K[ %nEnd of channel %W$0 %K- %W$1 %nbans counted %K]
# FSET BANS_HEADER #  Channel    SetBy        Sec  Ban
FSET FORMAT_BANS $[2]0 $[10]1 $[10]3 $[-5]tdiff($time() $4)  $2
FSET -BANS_FOOTER


#@ FSET FORMAT_KICK $G %n$3 was kicked off $2 by %c$1 %K(%n$4-%K)
FSET FORMAT_KICK $raf(${fg.nick}$3%n)  was kicked off ${fg.channelName}$2%n by ${fg.nick}$1%n $4-

#@FSET FORMAT_KICK_USER %K>%n>%W> %WYou%n have been kicked off %c$2%n by %c$1 %K(%n$4-%K)
p3fset FORMAT_KICK_USER $raf(${fg.nick}$1%n)! kicked you off ${fg.channelName}$2%n! $4-

#@ FSET FORMAT_NAMES $G %K[%GUsers%K(%g$1%K:%g$2%K)]%c $3
FSET FORMAT_NAMES ${fg.channelName}$([$nickWidth]1): users $2-

FSET FORMAT_NAMES_BANNER | 
@ namewidth = 13

# following doesn't work quite right yet:
# if ([$V] >= [19990221]) {
    # FSET FORMAT_NAMES_BANNER $([$nickWidth])| 
    # SET NAMES_COLUMNS 4
    # @ namewidth = 14
# }


#@ FSET -FORMAT_NAMES_BANNER
# the /names output is fixed in 5 colomns unfortunately
# format_names_banner is printed at the start of each line

# FSET FORMAT_NAMES_BOT $G %K[%GBots%K(%g$1%K:%g$2%K)]%c $3
# FSET FORMAT_NAMES_BOTCOLOR %K[%C$0%G$[10]1%K]

#@ FSET -FORMAT_NAMES_FOOTER
# this is used for the end of SCAN but not for the end of NAMES, it seems...
FSET FORMAT_NAMES_FOOTER   

# format_names_friend and so forth are for /scanf, /scano etc.
# $0 is timestamp, $1 is channel name, $2 is the count
#@ FSET FORMAT_NAMES_FRIEND $G %K[%GFriends%K(%g$1%K:%g$2%K)]%c $3
#@ FSET FORMAT_NAMES_IRCOP $G %K[%GIrcOps%K(%g$1%K:%g$2%K)]%c $3
#@ FSET FORMAT_NAMES_NONOP $G %K[%GNonChanOps%K(%g$1%K:%g$2%K)]%c $3
#@ FSET FORMAT_NAMES_OP $G %K[%GChanOps%K(%g$1%K:%g$2%K)]%c $3
#@ FSET FORMAT_NAMES_SHIT $G %K[%MShitUsers%K(%m$1%K:%m$2%K)]%c $3
#@ FSET FORMAT_NAMES_VOICE $G %K[%MVoiceUsers%K(%m$1%K:%m$2%K)]%c $3

FSET FORMAT_NAMES_FRIEND $raf(${fg.channelname}$1%n)  Friends: $2
FSET FORMAT_NAMES_IRCOP $raf(${fg.channelname}$1%n)  IRC Operators: $2
FSET FORMAT_NAMES_NONOP $raf(${fg.channelname}$1%n)  Non Channel Ops: $2
FSET FORMAT_NAMES_OP $raf(${fg.channelname}$1%n)  Channel operators: $2
FSET FORMAT_NAMES_SHIT $raf(${fg.channelname}$1%n)  Shitlisted: $2
FSET FORMAT_NAMES_VOICE $raf(${fg.channelname}$1%n)  Voiced: $2

# format_names_nickcolor and so forth are for /names and /sc and /scan details
#@ FSET FORMAT_NAMES_FRIENDCOLOR %C$0%Y$[13]1%K
#@ FSET FORMAT_NAMES_NICKCOLOR %B $[13]1%K
#@ FSET FORMAT_NAMES_OPCOLOR %C$0%n%B$[13]1%K
#@ FSET FORMAT_NAMES_SHITCOLOR %C$0%n%R$[13]1%K
#@ FSET FORMAT_NAMES_VOICECOLOR %Mv%B$[13]1%K]ds%K(%g$1%K:%g$2%K)]%c $3

# Colours here
# friend- cyan
# nick -- normal
# voice - magenta
# op ---- yellow
# "shit"- white
# this is all redefined later now.
FSET FORMAT_NAMES_FRIENDCOLOR %C$0%c$([$namewidth]1)%n
FSET FORMAT_NAMES_NICKCOLOR %n $([$namewidth]1)
FSET FORMAT_NAMES_VOICECOLOR %cv%m$([$namewidth]1)%K%n
FSET FORMAT_NAMES_OPCOLOR %c$0%n%y$([$namewidth]1)%n
FSET FORMAT_NAMES_SHITCOLOR %c$0%n%W$([$namewidth]1)%n


###################################
## Bot formats
# FSET FORMAT_BOT $[2]0 $[2]1 $[11]2 $[10]3 $4
# FSET FORMAT_BOT_FOOTER There are $1 on the BotList
# FSET FORMAT_BOT_HEADER Aop Prot Bot         Channel    Hostname

###################################
## server formats
# FSET FORMAT_CONNECT $G Connecting to server $1/%c$2%n
# FSET FORMAT_DISCONNECT $G Use %G/Server%n to connect to a server

#@ FSET FORMAT_LINKS %K�%n$[24]0%K� �%n$[24]1%K� �%n$[3]2%K� �%n$[13]3%K�

alias ilinks {
    ^local lbra [
    if ([$left(1, $0)]==[${lbra}]) {
	^local n ${[$@0]-[2]}
	^local ip $mid(1 $n $0)
	return $cparse("%c$laf(15 $ip)%n $1-")
    } else {
	return $cparse("$([15]) $0-")
    }
}

# FSET FORMAT_LINKS $raf($unnet($1))->%r$laf(12 $unnet($0))%n %c$raf($3) $4-%n $2
FSET FORMAT_LINKS $raf(${fg.Server}$ankhhub($1)%n)/${fg.Server}$laf(11 $unnet($0))%n$2 $ilinks($3-)

alias ankhhub {
    if ([$0] == links.server) {
	# don't print server name if it's the same
	return
    } else {
	@ links.server = [$0]
        return $unnet($0)
    }
}

# I should be using ON for this and trapping the numeric -- TODO
alias links {
    hline requesting link table for ${myNet}...
    @ links.server = []
    $K${K}links $0-
}

alias url {
    ^set -CONTINUED_LINE
    $K${K}url $0-
    ^set CONTINUED_LINE $([$nickWidth])${ankh.vline} 
}

# SERVER_PROMPT is printed before some, but not all, server messages.
# it's set to something non-empty now so I can see where it is used!
# so far,
# client_connect
# SET SERVER_PROMPT | 
SET -SERVER_PROMPT

# FSET FORMAT_SERVER $G%n $1: $2-
# FSET FORMAT_SERVER_MSG1 $G%n $1: $2-
# FSET FORMAT_SERVER_MSG1_FROM $G%n $1: $2-
# FSET FORMAT_SERVER_MSG2 $G%n $1-
# FSET FORMAT_SERVER_MSG2_FROM $G%n $1-

#@ FSET FORMAT_SERVER_NOTICE %G!%g$1%G%n $2-
FSET FORMAT_SERVER_NOTICE $raf(${fg.server}$unnet($1)${fg.error}!%n) $2-

# valinor.sorcery.net *** Notice -- Open socks server from [142.165.49.151]
# 0                   1   2      3  4    5     6      7    8
on ^server_notice "* Open socks server from *" {
    sockswarn $8
}

# sockswarn [ip]
alias sockswarn {
    @: ip
    if (left(1 $0) == [\[]) {
	@ ip = [$before(\] $mid(1 200 $0))]
    } else {
	@ ip = [$0]
    }
    hline
    echo $raf(${fg.server}server%n)${fg.error}!${nc} ${fg.error}open socks server from $ip${nc}
    who $ip
    @ :name = [$iptoname($ip)]
    if (name != []) {
	echo $raf(${fg.server}ankh.bx%n)${fg.error}!${nc} $ip is $name
	who $name
    }
}

# FSET FORMAT_SERVER_NOTICE_BOT Possible bot: %C$1 %K[%c$2-%K]%n
# FSET FORMAT_SERVER_NOTICE_BOT1 Possible $1 bot: %C$2 %K[%c$3-%K]%n

# FSET FORMAT_SERVER_NOTICE_BOT_ALARM $1 alarm activated: %C$2 %K[%c$3-%K]%n
#@ FSET FORMAT_SERVER_NOTICE_CLIENT_CONNECT Client Connecting: %C$1 %K[%c$2-%K]%n
FSET FORMAT_SERVER_NOTICE_CLIENT_CONNECT $raf(${fg.server}Client connect%n): ${fg.nick}$1%n $2-


#@ FSET FORMAT_SERVER_NOTICE_CLIENT_EXIT Client Exiting: %C$1 %K[%c$2-%K]%n
FSET FORMAT_SERVER_NOTICE_CLIENT_EXIT $raf(${fg.server}Client exit%n): ${fg.nick}$1%n $2-

# FSET FORMAT_SERVER_NOTICE_CLIENT_INVALID Invalid username: %C$1 %K[%c$2-%K]%n
# FSET FORMAT_SERVER_NOTICE_CLIENT_TERM Terminating client for excess flood %C$1%K [%c$2-%K]%n
# FSET FORMAT_SERVER_NOTICE_FAKE Fake Mode detected on $1 -> $2-
# FSET FORMAT_SERVER_NOTICE_GLINE %W$1%n added a new K-Line %K[%c$2%K]%n from $3 for $4-

#@ FSET FORMAT_SERVER_NOTICE_KILL Foreign OperKill: %W$1%n killed %c$2%n %K(%n$3-%K)%n
# this happens when an oper on another server uses /kill
# FSET FORMAT_SERVER_NOTICE_KILL [$1 killed $2 $3-]
FSET -FORMAT_SERVER_NOTICE_KILL
# p3set -FORMAT_SERVER_NOTICE_KILL
# p3set -FORMAT_SERVER_NOTICE_KILL_LOCAL

#@ FSET FORMAT_SERVER_NOTICE_KILL_LOCAL Local OperKill: %W$1%n killed %c$2%n %K(%n$3-%K)%n
# an operator on this server killed someone
FSET FORMAT_SERVER_NOTICE_KILL_LOCAL $raf(${fg.server}$0%n)  [$Z] ${fg.server}$1 killed $2: $3-]
#FSET -FORMAT_SERVER_NOTICE_KILL_LOCAL

# FSET FORMAT_SERVER_NOTICE_KLINE %W$1%n added a new K-Line %K[%c$2%K]%n for $3-
# FSET FORMAT_SERVER_NOTICE_NICKC Nick collision8 %W$1%n killed %c$2%n %K(%n$3-%K)%n

#@ FSET FORMAT_SERVER_NOTICE_OPER %C$1 %K[%c$2%K]%n is now %Wa%w %GIRC%n operator
FSET FORMAT_SERVER_NOTICE_OPER $raf(${fg.nick}$1%n)  [$2] is now an IRC operator

# FSET FORMAT_SERVER_NOTICE_REHASH %W$1%n is rehashing the Server config file
FSET FORMAT_SERVER_NOTICE_REHASH $raf(${fg.nick}$1%n)  rehashed the server config file

# FSET FORMAT_SERVER_NOTICE_STATS Stats $1: %C$2 %K[%c$3-%K]%n
# FSET FORMAT_SERVER_NOTICE_TRAFFIC_HIGH Entering high-traffic mode %K(%n$1 > $2-%K)%n
# FSET FORMAT_SERVER_NOTICE_TRAFFIC_NORM Resuming standard operation %K(%n$1 $2 $3-%K)%n
# FSET FORMAT_SERVER_NOTICE_UNAUTH Unauthorized Connection from $1-
# FSET FORMAT_NETADD $G %nAdded: %W$1 $2

#@ FSET FORMAT_NETJOIN $G %nNetjoined: %W$1 $2
# $0 is the time stamp, 1 and 2 are the server names
FSET FORMAT_NETJOIN $raf(${fg.error}Netjoined%n): ${fg.Server}$unnet($1)%n/${fg.server}$unnet($2)%n [$0]

#@ FSET FORMAT_NETSPLIT $G %nNetSplit: %W$1%n split from %W$2 %K[%c$0%K]
FSET FORMAT_NETSPLIT $raf(${fg.error}NetSplit%n): ${fg.Server}$unnet($1)%n split from ${fg.server}$unnet($2)%n [$0]
# FSET -FORMAT_NETSPLIT_HEADER

# FSET FORMAT_WHOLEFT_HEADER %G������ %WWho %G�����%g---%G���%g--%G�����%g�-%G�� %WChannel%g��� %wServer %G-%g��--%G��%g--%G����%g %wSeconds
# FSET FORMAT_WHOLEFT_USER %G|%n $[-10]0!$[20]1 $[10]2 $[20]4 $3

### stats stuff

# stats u
on ^242 "*" /echo $raf(${fg.server}$unnet($0)%n): $1-
on ^250 "*" /echo $raf(${fg.server}$unnet($0)%n): $1-


###

###################################
## channel formats

# In general, the channel name is in cyan (%c), and I have left
# host masks visible in both join and part messages with no clutter
# around them, so you can easily copy and paste them, e.g. for a ban :)
#
# join and part messages have a small piece of red in them so they are
# more easily found when you scroll back.  The joined message is in
# bold so it stands out more than the "parts" one.
#
alias mkprompt {
    if ([$Q] != []) {
	return $rnt(->${fg.privmsg}$Q%n)
    } {
	return $rnt(${fg.channelName}$C%n)
    }
}

alias me {
    if ([$Q] != []) {
	qme $0-
    } else {
	//me $0-
    }
}

#@SET INPUT_PROMOT [$C] 
SET INPUT_PROMPT $mkprompt(): 

#@FSET FORMAT_CHANNEL_SIGNOFF $G %nSignOff %W$1%n: $3 %K(%n$4-%K)
FSET FORMAT_CHANNEL_SIGNOFF $raf(${fg.Nick}$1%n)%r->signoff%n ${fg.channelName}$3%n $2 ($stripansicodes($4-))
#@ FSET FORMAT_INVITE %K>%n>%W> $1 Invites You to $2-
FSET FORMAT_INVITE $raf(${fg.nick}$1%n)  Invites you to ${fc.channelName}$2%n $3-

#@ FSET FORMAT_INVITE_USER %K>%n>%W> Inviting $1 to $2-
FSET FORMAT_INVITE_USER $raf(${fg.channelname}$2%n): Inviting ${fg.nick}$1%n $3-

# FSET FORMAT_IGNORE_INVITE %K>%n>%W> You have been invited to $1-
FSET FORMAT_IGNORE_INVITE $raf(${fg.channelName}$1%n)  You have been invited to ${raf.channelName}$1-%n

#@ FSET FORMAT_DESYNC $G $1 is desynced from $2 at $0
FSET FORMAT_DESYNC $raf(${fg.channelname}$1%n)  desynced from $2 at $0

#@ FSET FORMAT_JOIN $G %C$1 %K[%c$2%K]%n has joined $3
# make someone joining a channel fairly visible, usr %R (bold red):
FSET FORMAT_JOIN $raf(${fg.Nick}$1%n)%R<-joined%n ${fg.channelName}$3%n $2

#@ FSET FORMAT_LEAVE $G $1 %K[%w$2%K]%n has left $3 %K[%W$4%K]
#FSET FORMAT_LEAVE $([$nickWidth]3): left: %k$1%n $2 ($4-)
FSET FORMAT_LEAVE $raf(${fg.Nick}$1%n)%r->left%n ${fg.channelName}$3%n $2 ($stripansicodes($4-))

#@ FSET FORMAT_LIST $[12]1 $[-5]2   $[40]3-
# FSET FORMAT_LIST $raf(%p$2%n): ${fg.channelName}$1%n $2-
FSET FORMAT_LIST $raf(${fg.channelname}$1%n)%r$[-4]2%n $3-

#@ FSET FORMAT_MODE $G %nmode%K/%c$3 %K[%W$4-%K]%n by %W$1
FSET FORMAT_MODE $raf(${fg.nick}$1%n)  sets mode [${fg.ChannelName}$3%n $4-]

#@ FSET FORMAT_MODE_CHANNEL $G %nmode%K/%c$3 %K[%W$4-%K]%n by %W$1
FSET FORMAT_MODE_CHANNEL $raf(${fg.channelName}$3%n): mode [%c$4-%n] by $1

#@ FSET FORMAT_TOPIC $G Topic for %c$1%K:%n $2-
FSET FORMAT_TOPIC $raf(${fg.channelName}$1%n): Topic: $2-
#@ FSET FORMAT_TOPIC_CHANGE $G %W$1 %nhas changed the topic on channel $2 to%K:%n $3-
FSET FORMAT_TOPIC_CHANGE ${fg.channelName}$([$nickWidth]2)%n  ${fg.channelName}topic%n $3-%n (${fg.nick}$1)%n

# FSET -FORMAT_TOPIC_CHANGE_HEADER
#@ FSET FORMAT_TOPIC_SETBY $G %ntopic set by %c$2%K [%c$stime($3)%K]
FSET FORMAT_TOPIC_SETBY $([$nickWidth]): topic set by $2 [$stime($3)]

# FSET FORMAT_TOPIC_UNSET $G %ntopic unset by $1 on $2
FSET FORMAT_TOPIC_UNSET $raf(${fg.channelName}$1%n): topic unset on ${fg.channelName}$2%n

# channel join: 329 is sent with the channel creation date - who cares?
# I could possibly trap and see if it was created now, and say so
on ^329 "*"
# /on ^329 "*" /echo $raf(%c$1%n) created $stime($2)

###################################
## nicks and clients

# FSET FORMAT_IGNORE_MSG %K[%P$1%P$2%K(%p$3%K)]%n $4-
# FSET FORMAT_IGNORE_MSG_AWAY %K[%P$1%P$2%K(%p$3%K)]%n $4-
# FSET FORMAT_IGNORE_NOTICE %K-%P$2%K(%p$3%K)-%n $4-
# FSET FORMAT_IGNORE_WALL %K%P$1%n $2-

#@FSET FORMAT_NICKNAME $G %W$1 %nis now known as %c$3
FSET FORMAT_NICKNAME $raf(${fg.nick}$1%n)  is now known as ${fg.nick}$3%n

#@ FSET FORMAT_NICKNAME_OTHER $G %W$1 %nis now known as %c$4
FSET FORMAT_NICKNAME_OTHER $raf(${fg.nick}$1%n)  is now known as ${fg.nick}$4%n [$3]

#@ FSET FORMAT_NICKNAME_USER %K>%n>%W> %WYou%K(%n$1%K)%n are now known as %c$3
FSET FORMAT_NICKNAME_USER $raf(${fg.MyNick}$1%n)  changed nick to ${fg.MyNick}$3%n

#@ FSET FORMAT_NICK_AUTO $0:$1-
# nick completion with control-] or whatever
FSET FORMAT_NICK_AUTO $0:$1-

# p3set FORMAT_COMPLETE %K[%n$[15]0%K] [%n$[15]1%K] [%n$[15]2%K] [%n$[15]3%K]

#@ FSET FORMAT_NICK_COMP $0:$1-
# nick completion (usually with control-]) pastes this:
FSET FORMAT_NICK_COMP $0:$1-

# FSET FORMAT_NICK_MSG $0 $1 $2-

#@ FSET FORMAT_NONICK %W$1%K:%n $3-
# server message: no such nick/channel
FSET FORMAT_NONICK $raf(%gserver%n): $unnet($1): $3-


# FSET FORMAT_NOTIFY_OFF $[10]0 $[35]1 $[-6]2 $[-10]3 $4 $5
# FSET FORMAT_NOTIFY_ON $[10]0 $[35]1 $[-6]2 $[-10]3 $4-
FSET FORMAT_NOTIFY_ON $raf(notify): $[10]0 $[35]1 $[-6]2 $[-10]3 $4-
FSET FORMAT_NOTIFY_OFF $raf(notify): $[10]0 $[35]1 $[-6]2 $[-10]3 $4 $5

# FSET FORMAT_NOTIFY_SIGNOFF $G %GSignoff%n by %r$[10]1%n at $0
FSET FORMAT_NOTIFY_SIGNOFF $raf(notify): Signoff by ${fg.nick}$1%n at $0

# p1set FORMAT_NOTIFY_SIGNOFF_UH $G %GSignoff%n by %r$1%K!%r$2%n at $0
# FSET FORMAT_NOTIFY_SIGNON $G %GSignon%n by %r$[-10]1%n at $0
# p1set FORMAT_NOTIFY_SIGNON_UH $G %GSignon%n by %R$1%K!%R$2%n at $0

#@ FSET FORMAT_WHO %Y$[10]0 %W$[10]1%w %c$[3]2 %w$3%R@%w$4 ($6-)
FSET FORMAT_WHO $raf(${fg.nick}$1%n)${ankh.vline} ${fg.channelName}$0%n $3@$4/${fg.server}$unnet($5)%n $2 

##

# FSET FORMAT_FLOOD %Y$1%n flood detected from %G$2%K(%g$3%K)%n on %K[%G$4%K]
# FSET FORMAT_HELP $0-
#@ FSET FORMAT_MAIL %K>%n>%W> You've got mail!@#
FSET FORMAT_MAIL $G You have mail.

# FSET FORMAT_MSGCOUNT [$0-]
# FSET FORMAT_MSGLOG [$[8]0] [$1] - $2-

# msg group is for when someone does msg @#channel for example
# FSET FORMAT_MSG_GROUP %K-%P$1%K:%p$2%K-%n $3-

# FSET FORMAT_NOTE ($0) ($1) ($2) ($3) ($4) ($5-)

# FSET FORMAT_PASTE %K[%W$1%K]%n $2-

# FSET FORMAT_REL %K[%rmsg->$1%K]%n $4-
# FSET FORMAT_RELM %K[%P%P$1%K(%p$2%K)]%n $4-
# FSET FORMAT_RELN %K-%P$1%K(%p$2%K)-%n $4-
# FSET FORMAT_RELS $1-
# FSET FORMAT_RELSM %K[%rmsg%K(%R$1%K)] %n$2-
# FSET FORMAT_RELSN %K[%rnotice%K(%R$1%K)] %n$2-

# FSET FORMAT_SEND_AWAY [Away ($strftime($1 %a %b %d %I:%M%p %Z))] [$tdiff2(${time() - u})] [BX-MsgLog $2]



# FSET FORMAT_SET %g$[-30.]0 %w$1-
# FSET FORMAT_SET_NOVALUE %g$[-30.]0 has no value

# FSET FORMAT_SHITLIST  $[3]0 $[34]1 $[10]2  $3-
# FSET FORMAT_SHITLIST_FOOTER There are $1 users on the shitlist
# FSET FORMAT_SHITLIST_HEADER  lvl nick!user@host                     channels   reason

# FSET FORMAT_SIGNOFF $G %nSignOff: %W$1 %K(%n$3-%K)
# FSET FORMAT_SILENCE $G %RWe are $1 silencing $2 at $0
# FSET FORMAT_SMODE $G %RServerMode%K/%c$3 %K[%W$4-%K]%n by %W$1
FSET FORMAT_SMODE $raf(${fg.server}ServerMode%n)/ ${fg.channelname}$3%n $4- by ${fg.server}$1%n

###################################
## Windows
# FSET FORMAT_WINDOW_SET $0-

#@ FSET FORMAT_STATUS %4%W$0-
FSET FORMAT_STATUS %W$0-

#@ FSET FORMAT_STATUS1 %4%W$0-
FSET FORMAT_STATUS1 %W$0-

#@ FSET FORMAT_STATUS2 %4%W$0-
FSET FORMAT_STATUS2 %W$0-

#@ FSET FORMAT_STATUS3 %4%W$0-
FSET FORMAT_STATUS3 %W$0-

alias _wset {
    set $0-
    wset $0-
}

SET DOUBLE_STATUS_LINE 0
_WSET FULL_STATUS_LINE ON
_WSET REVERSE_STATUS OFF
_WSET SHOW_STATUS_ALL OFF
_WSET STATUS_AWAY  (zZzZ %A)
_WSET STATUS_CDCCCOUNT [CDCC gets/%| offer/%|]
_WSET STATUS_CHANNEL %C
_WSET STATUS_CHANOP @
_WSET STATUS_CLOCK %T
_WSET STATUS_CPU_SAVER  (%J)
_WSET STATUS_DCCCOUNT [DCC  gets/%& sends/%&]
_WSET STATUS_DOES_EXPANDOS OFF
# SET STATUS_FLAG 
# SET STATUS_FORMAT  [0;44;36m[[1;37m%T[0;44;36m][%@%=[0;44;37m%N%#%A[0;44;36m]%M [0;44;36m[%C%+%W[0;44;36m] %Q %H%B%F 

#@ SET STATUS_FORMAT1  [0;44;36m[[1;37m%T[0;44;36m][[1;37m%@%=[0;44;37m%N%#%A[0;44;36m]%M [0;44;36m[%C%+%W[0;44;36m] %Q %H%B%F 
# _WSET STATUS_FORMAT [37;46m%W[%T][%@%=%N%#%A]%M [%C%+%W] %Q %H%B%F% (F)>%L
_WSET STATUS_FORMAT [1;34;47m[37;46m%W[%T][%@%=%N%#%A]%M [%C%+%W] %Q %H%B%F% (F)>%L
_WSET STATUS_FORMAT1 [37;46m%W[%T][%@%=%N%#%A]%M [%C%+%W] %Q %H%B%F%>%L

#% SET STATUS_FORMAT2 [%L %! %K %>%D %J[%u:%a:%f:%b:%h]
_WSET STATUS_FORMAT2  [%T]
win double off

# SET STATUS_FORMAT3 BitchX by panasync 
# SET STATUS_HALFOP %
# SET STATUS_HOLD  -- more --

#@ SET STATUS_HOLD_LINES  [0;44;36m([1;37m%B[0;44m)[0;44;37m
_WSET STATUS_HOLD_LINES  (%B)

# SET STATUS_INSERT 

#@ SET STATUS_LAG [0;44;36m[[0;44;37mLag [1;37m%L[0;44;36m]
_WSET STATUS_LAG [Lag: %L]

#@ SET STATUS_MAIL [0;44;36m[[0;44;37mMail: [1;37m%M[0;44;36m]
_WSET STATUS_MAIL [Mail: %M]

#@ SET STATUS_MODE [1;37m([0;44;36m+[0;44;37m%+[1;37m)
_WSET STATUS_MODE (+%+)

# SET STATUS_MSGCOUNT  Aw[0;44;36m[[1;37m%^[0;44;36m]
_WSET STATUS_MSGCOUNT  Aw[%^]

# SET STATUS_NICK %N
#@ SET STATUS_NOTIFY  [0;44;36m[[37mAct: [1;37m%F[0;44;36m]
_WSET STATUS_NOTIFY  [Act: %F]
# SET STATUS_NO_REPEAT ON
#@ SET STATUS_OPER [1;31m*[0;44;37m
_WSET STATUS_OPER *

#@ SET STATUS_OPER_KILLS [0;44;36m[[37mnk[36m/[1;37m%K [0;44mok[36m/[1;37m%K[0;44;36m]
_WSET STATUS_OPER_KILLS [nk/%K ok/%K]

# SET STATUS_OVERWRITE (overtype) 

#@ SET STATUS_QUERY  [0;44;36m[[37mQuery: [1;37m%Q[0;44;36m]
_WSET STATUS_QUERY  [Query: %Q]

# SET STATUS_SCROLLBACK  (Scroll)
# SET STATUS_SERVER  via %S
# SET STATUS_TOPIC %-
#@ SET STATUS_UMODE [1;37m([0;44;36m+[37m%#[1;37m)
_WSET STATUS_UMODE (+%#)
# SET STATUS_USER0  * type /help for help 
# SET STATUS_USER1 
# SET STATUS_USER10 
# SET STATUS_USER11 
# SET STATUS_USER12 
# SET STATUS_USER13 
# SET STATUS_USER14 
# SET STATUS_USER15 
# SET STATUS_USER16 
# SET STATUS_USER17 
# SET STATUS_USER18 
# SET STATUS_USER19 
# SET STATUS_USER2 
# SET STATUS_USER3 
# SET STATUS_USER4 
# SET STATUS_USER5 
# SET STATUS_USER6 
# SET STATUS_USER7 
# SET STATUS_USER8 
# SET STATUS_USER9 
#@ SET STATUS_USERS [0;44;36m[[37mO[36m/[1;37m%! [0;44mN[36m/[1;37m%! [0;44mI[36m/[1;37m%! [0;44mV[36m/[1;37m%! [0;44mF[36m/[1;37m%![0;44;36m]
_WSET STATUS_USERS [O/%! N/%! I/%! V/%! F/%!]
#@ SET STATUS_VOICE [1;32m+[0;44;37m
_WSET STATUS_VOICE +

# this is shown only in the current window
# SET STATUS_WINDOW [1;44;33m^^^^^^^^[0;44;37m
_WSET STATUS_WINDOW [1;34;47m

### ansi colour reference
# ESC [ Ps m
#     Character Attributes (SGR)
#     Ps = 0 : Normal (default)
#     Ps = 1 / 22 : On / Off Bold (bright fg)
#     Ps = 4 / 24 : On / Off Underline
#     Ps = 5 / 25 : On / Off Blink (bright bg)
#     Ps = 7 / 27 : On / Off Inverse
#     Ps = 30 / 40 : fg / bg Black
#     Ps = 31 / 41 : fg / bg Red
#     Ps = 32 / 42 : fg / bg Green
#     Ps = 33 / 43 : fg / bg Yellow
#     Ps = 34 / 44 : fg / bg Blue
#     Ps = 35 / 45 : fg / bg Magenta
#     Ps = 36 / 46 : fg / bg Cyan
#     Ps = 37 / 47 : fg / bg White
#     Ps = 39 / 49 : fg / bg Default
#


# FSET FORMAT_TIMER $G $[-5]0 $[-10]1 $[-6]2 $3-
# FSET FORMAT_TRACE_OPER %R$1%n %K[%n$3%K]
# FSET FORMAT_TRACE_SERVER %R$1%n $2 $3 $4 %K[%n$5%K]%n $6-
# FSET FORMAT_TRACE_USER %R$1%n %K[%n$3%K]
# FSET FORMAT_USAGE $G Usage: /$0  $1-

#@ FSET FORMAT_USERMODE $G %nMode change %K[%W$4-%K]%n for user %c$3
FSET FORMAT_USERMODE $raf(${fg.nick}$3%n)--umode %c$4-%n

alias ankhversionsetter {
    @ aver = [$2]
}
ankhversionsetter $Id: ankh.bx,v 1.39 2002/02/04 23:27:15 lee Exp $
alias -ankhversionsetter

#@ FSET FORMAT_VERSION $0+$4$5 by panasync - $2 $3
# this is used for the /sv command (show version in current channel) and
# also for the ctcp version reply:
FSET FORMAT_VERSION $0+$4$5+[ankh/${aver}] by panasync - $2 $3

#@ FSET FORMAT_WALL %G!%g$1:$2%G!%n $3-
FSET FORMAT_WALL $raf(${fg.Globals}WALL%n) ${fg.nick}$1%n $3-

#@ FSET FORMAT_WALLOP %G!%g$1$2%G!%n $3-
FSET FORMAT_WALLOP WALLOP %G!%g$1$2%G!%n $3-

#@ FSET FORMAT_WALL_AR %G!%g$1:$2%G!%n $3-
FSET FORMAT_WALL_AR WALL-AutoReply %G!%g$1:$2%G!%n $3-

###################################
## whois


#@ FSET FORMAT_WHOIS_HEADER %G������---%g�%G--%g��%G-%g������---%K�%g--%K��%g-%K���������--- --  -
# a blank line before the whois reply sets it off just fine without
# all that character-set-specific nonsense:
FSET FORMAT_WHOIS_HEADER  

#@ FSET FORMAT_WHOIS_ADMIN %K| %Wa%ndmin    : $0 - $1-
FSET FORMAT_WHOIS_ADMIN $raf(admin): $0 - $1-

#@ FSET FORMAT_WHOIS_AWAY %K| %Wa%nway     : $0 - $1-
FSET FORMAT_WHOIS_AWAY $raf(away): $0 - $1-

#@ FSET FORMAT_WHOIS_BOT %g| %Wb%not      : A:$0 P:$1 [$2] $3-
FSET FORMAT_WHOIS_BOT $raf(bot): A:$0 P:$1 [$2] $3-

#@ FSET FORMAT_WHOIS_CHANNELS %g| %Wc%nhannels : $0-
FSET FORMAT_WHOIS_CHANNELS $raf(channels): $0-

#@ FSET FORMAT_WHOIS_FRIEND %g| %Wf%nriend   : F:$0 $1-
FSET FORMAT_WHOIS_FRIEND $raf(friend): F: $0 $1-

#@ FSET FORMAT_WHOIS_HELP %K| %Wh%nelp     : $0 - $1-
FSET FORMAT_WHOIS_HELP $raf(helpop): $0 - $1-

#@ FSET FORMAT_WHOIS_IDLE %K: %Wi%ndle     : $0 hours $1 mins $2 secs (signon: $stime($3))
FSET FORMAT_WHOIS_IDLE $raf(idle): $0 hours $1 mins $2 secs (signon: $stime($3))

#@ FSET FORMAT_WHOIS_NAME %G� %Wi%nrcname  : $0-
FSET FORMAT_WHOIS_NAME $raf(ircname): $0-

#@ FSET FORMAT_WHOIS_NICK %G| %W$0 %K(%n$1@$2%K) %K(%W$3-%K)
FSET FORMAT_WHOIS_NICK $raf(${fg.nick}$0%n): ($1@$2) $3-

#@ FSET FORMAT_WHOIS_OPER %K| %Wo%nperator : $0 $1-
# FSET FORMAT_WHOIS_OPER $raf(operator): $0-
FSET FORMAT_WHOIS_OPER $raf(operator): is an IRC operator
on ^313 "*" /echo $raf(operator): $1-
on ^309 "*" /echo $raf(silenced): $1-
on ^550 "*" /echo $raf(IP mask): $5-

#@ FSET FORMAT_WHOIS_REGISTER %K| %Wr%negister : $0 - $1-
FSET FORMAT_WHOIS_REGISTER $raf(registered): $0 - $1-

#@ FSET FORMAT_WHOIS_SERVER %K� %Ws%nerver   : $0 ($1-)
FSET FORMAT_WHOIS_SERVER $raf(server): $0 - $1-

#@ FSET FORMAT_WHOIS_SERVICE %K| %Ws%nervice  : $0 - $1-
FSET FORMAT_WHOIS_SERVICE $raf(service): $0 - $1-

#@ FSET FORMAT_WHOIS_SHIT %g| %Ws%nhit     : L:$0 [$1] $2 $3-
FSET FORMAT_WHOIS_SHIT $raf(shitlist): L:$0 [$1] $2 $3-

#@ FSET FORMAT_WHOIS_SIGNON %K %Ws%nignon   : $0-
FSET FORMAT_WHOIS_SIGNON $raf(signon): $0-

#@ FSET -FORMAT_WHOIS_FOOTER
FSET FORMAT_WHOIS_FOOTER  

#@ FSET -FORMAT_WHOLEFT_FOOTER
SET -FORMAT_WHOLEFT_FOOTER

#@ FSET FORMAT_WHOWAS_HEADER %G������---%g�%G--%g��%G-%g������---%K�%g--%K��%g-%K���������--- --  -
FSET FORMAT_WHOWAS_HEADER    

#@ FSET FORMAT_WHOWAS_NICK %G| %W$0%n was %K(%n$1@$2%K)
FSET FORMAT_WHOWAS_NICK $raf(${fg.nick}$0%n)  was $1@$2
# FSET FORMAT_WIDELIST $1-

#@ FSET -FORMAT_XTERM_TITLE
# FSET FORMAT_XTERM_TITLE ]2;$0-


alias globops quote globops :$0-
alias locops quote locops :$0-
# alias helpop quote help :$0-
alias ns quote nickserv $0-
alias cs quote chanserv $0-
alias os quote operserv $0-
alias ms quote memoserv $0-
alias is quote infoserv $0-
alias ns quote nickserv $0-

# hurt is specific to SorceryNet
alias hurt quote hurt :$0-


####
# aconf -- online configuration
# /aconf nskill show|hide
alias aconf {
    ^local ok
    @ ok = 0;
    if ([$0]==[nskill]) {
	if (([$1] == [show]) || ([$1] == [hide])) {
	    @ ShowNickServKills = [$1]
	    echo $raf(${fg.Help}aconf%n): NickServ kills set to: $1
	} {
	    echo $raf(${fg.error}mishap%n): you must follow nskill with either show or hide, not "$1"
	    echo $raf()  /aconf nskill show -- NickServ kills will be shown
	    echo $raf()  /aconf nskill hide -- NickServ kills will not be shown
	    echo $raf()  nskill current setting: $ShowNickServKills
	}
	@ ok = 1;
    }

    # TODO use a hook to catch setting show_numerics on/off
    if ([$tolower($0)] == [usepcfont]) {
	if ([$1] == [yes] || [$1] == [no]) {
	    @ usePCfont = [$1]
	    if ([$usepcfont] == [yes]) {
		ankh.setline �
		@ G = [$cparse(%W�%n��)]
	    } {
		ankh.setline |
		@ G = [***]
	    }
	    ^set show_numerics_str $G
	    echo $raf(${fg.Help}aconf%n): usePCfont set to: $usePCfont
	} {
	    if ([$1] != []) {
		echo $raf(${fg.error}mishap%n): unkown usePCfont option [$1]
	    }
	    echo $raf(${fg.error}mishap%n): you must follow usePCfont with either yes (to say that you are using a PC font) or no (e.g. if � is an A with an acute accent over it on your screen, you should probably use "no")
	}
	@ ok = 1;
    }

    if ([$0] == [network]) {
	@ ok = 1
	if ([$1] == []) {
	    echo $raf(${fg.Help}usage%n): /aconf network sorcery.net -- the string you give here will be stripped off server messages and /links output to make it easier to read.  Current value is $myNet
	} {
	    @ myNet = [$1]
	    echo $raf(${fg.Help}aconf%n): .$1 will be removed from server names in /links and elsewhere.
	}
    }

    if ([$0] == [list]) {
	@ ok = 1
	if ([$1] == [users]) {
	    @ listSortField = [users]
	    echo $raf(${fg.Help}aconf%n): /list output will be sorted by the number of users in the channel.
	    echo $raf(${fg.Help}aconf%n): caution: this is not implemented correctly.
	} {
	    @ listSortField = [name]
	    echo $raf(${fg.Help}aconf%n): /list output will be sorted by the channel name.
	    echo $raf(${fg.Help}aconf%n): use /aconf list users if you would like to sort by the number of users.
	}
    }

    if ([$0] == [load]) {
	@ ok = 1
	_ainternal-loadconf $1-
    }

    if ([$0] == [save]) {
	@ ok = 1
	_ainternal-saveconf $1-
    }

    if ([$0] == [theme]) {
	@ ok = 1
	loadTheme $1-
    }

    if ([$0] == [timestamp]) {
	@ ok = 1
	if ([$1] == []) {
	    echo $raf(${fg.Help}usage%n): /aconf timestamp off|n to timestamp every n minutes in the left margin.  Use /themeset timestamp to change the colour of the timestamp.
	    return
	}
	if ([$1] == [off]) {
	    @ ankh.ts = -1
	    echo $raf(${fg.Help}timestamp%n): set to ${fg.Help}off%n
	} {
	    if (isnumber($1) || isnum($1)) {
		@ ankh.ts = [$1]
		echo $raf(${fg.Help}timestamp%n): set to $ankh.ts
	    } {
		echo $raf(${fg.error}mishap%n): you must follow timestamp with the word off or a number, not "$1".  For example, /aconf timestamp 3 would put a timestamp in the left margin approximately once every 3 minutes.  Use 0 to put it everywhere.
	    }
	    @ ankh
	}
    }

    if ([$0] == []) {
	hline ${fg.Help}aconf: ankh.bx configuration%n
	oneHelp nskill show/hide NickServ kill messages [now $ShowNickServKills]
	oneHelp network set current network suffix [now $myNet]
	oneHelp theme load the named theme\; use -list as a theme name to see a list of available themes.
	oneHelp usePCfont yes/no to say whether to use PC line drawing characters and the famous BitchX Blob (���)
	oneHelp list users|names to say how to sort /LIST output
	oneHelp timestamp off|n to show a timestamp every n minutes or so
	oneHelp save to save current settings
	oneHelp load to load settings from $ANKHDIR/aconf.bx
	oneHelp Note: if you do not use /aconf save, your aconf settings will be lost when you quit BitchX.
	@ ok = 1;
    }

    if ([$ok] == [0]) {
	hline ${fg.Help}aconf: ankh.bx configuration%n
	oneHelp usage /aconf setting value... do /ahelp by itself for a list of settings.
    }
    echo
}

# all variables in the avar array are saved when you save configuration
@avar.myNet = [myNet]
@avar.usePCfont = [usePCfont]
@avar.ShowNickServKills = [ShowNickServKills]
@avar.timestamp = [ankh.ts]
@avar.listSortField = [listSortField]
@listSortField = [name]

alias aload {
    if ([$0] == [conf]) {
	if (fexist($ANKHDIR/aconf.bx)) {
	    load $ANKHDIR/aconf.bx
	}
    } {
	load ${ANKHDIR}/ankh.bx
    }
    doPCfont
}

alias _ainternal-loadconf {
    if (fexist($ANKHDIR/aconf.bx)) {
	load $ANKHDIR/aconf.bx
    } {
	echo $raf(${fg.error}mishap%n): no saved configuration file was found -- either you have not yet used /aconf save, or ANKHDIR is set incorrectly.  I looked for configuration file $ANKHDIR/aconf.bx
    }
}

alias _ainternal-saveconf {
    ^local fname $ANKHDIR/aconf.bx

    if ([$fexist($ANKHDIR/themes/plain.bx)] == [-1]) {
	echo $raf(${fg.error}mishap%n): Your ankh.bx script is not installed properly:
	echo $raf(${fg.error}mishap%n): The file $ANKHDIR/themes/plain.bx isn't there, of you don't have permission to read it... check ANKHDIR is set properly in the script.
    }

    @ unlink($fname)

    ^local fd
    @ fd = [$open($fname W)]
    if ([$fd] == [-1]) {
	echo $raf(${fg.error}mishap%n): Could not save settings to $fname (make sure the directory $ANKHOME is there and that you have permission to write to it; if not, change the definition of ANKHOME in the ankh.bx script.
	return
    }

    @ write($fd # aconf.bx -- configuration saved for $N)

    ^local cname
    foreach avar cname
    {
	@ write($fd @ $avar[$cname] = [$($avar[$cname])])
    }

    # make it print a message when it is loaded:
    @ write($fd /echo $raf(aload): loaded configuration $fname)

    if ([$close($fd)] == [-1]) {
	echo
	echo $raf(${fg.error}mishap%n): error on closing $fname -- check the disk is not full!
	exec df $ANKHDIR
	hline
	return
    }

    hline ${fg.Help}configuration saved to $fname%n
}

#########
# list channels
# :valinor.sorcery.net 321 boy Channel :Users  Name
# :valinor.sorcery.net 322 boy #sorcery 9 :SorceryNet Administrative Channel -- Welcome! :)
# :valinor.sorcery.net 323 boy :End of /LIST

alias list {
    @ channelcount = 0
    @ delarray(channels_n)
    //list $0-
}

on ^321 "*" { # start channel listing
    set show_end_of_msgs on
    @ channelcount = 0
    @ delarray(channels_n)
    on ^323 "*" /end_list
    return 1
}

on ^322 "*" {
    if ([$1] == [*]) {
	# @ channels[$channelcount].topic = [(private or secret channel)]
	# @ channelcount++
	return 1
    }
    @ channels[$channelcount].name = [$1]
    @ channels[$channelcount].users = [$2]
    @ channels[$channelcount].topic = [$3-]
    if (listSortField == [users]) {
	$setitem(channels_n ${channelcount} $2)
    } {
	@ :name = [$tolower($1)]
	$setitem(channels_n ${channelcount} $name)
    }
    @ channelcount++
    return 1
}

alias end_list {
    set show_end_of_msgs off
    hline
    @ :red = [$setColour(%r)]
    for (@ i = 0, i < channelcount, @ i++) {
	@ :stuff = [$igetitem(channels_n $i)]
	@ :cc = [$finditem(channels_n $stuff)]
	@ :name = channels[$cc].name
	echo $raf(${fg.channelname}${name}%n)${ankh.vline}${red}$[-3]{channels[$cc][users]}$nc $channels[$cc][topic]
    }
    echo
    for (@ i = 0, i < channelcount, @ i++) {
        ^assign -channels[$i].name
        ^assign -channels[$i].users
        ^assign -channels[$i].topic
    }
    $delarray(channels_n)
    @ channelcount = 0
    return 1
}


#########
# who is in a channel
# we generate these sorted into 3 lists:
# names_ops
# names_v
# names_n
# then we sort the lists
alias names {
    @ namecount = 0
    @ widest_nick = 1
    $K${K}names $0-
}

alias sc {
    @ namecount = 0
    @ widest_nick = 1
    $K${K}sc $0-
}

@ in_names = 0

on ^353 "*" {
    if (!in_names) {
	@ in_names++
	@ namecount = 0
	@ widest_nick = 1
    }
    @ :i = 0
    fe ($3-) i {
	# take a leading @ or + and put it at the end
	# BUG there is no way to tell if someone is +o and +v
	@ :orig = [$i]
	@ :flag = [n]
	switch ( $left(1 $i) ) {
	    (@) {
	       @ flag = [op]
	    }
	    (+) {
	       @ flag = [v]
	    }
	    (*) {
	       @ flag = [n]
	       # add a char so we can chop it off again:
	       @ orig = [n] ## orig
	    }
	}
	# chop off the first character(the flag):
	@ orig = mid(1 1000 $orig)
	@ thenick = [$tolower($orig)]
	$setitem(names_n ${namecount} $thenick ${flag} $orig)
	if ([$@thenick] > widest_nick) {
	    @ widest_nick = [$@thenick]
	}
	@ namecount++
    }
    set show_end_of_msgs on
    on ^366 "*" end_names $2
    return 1
}

alias end_names {
    set show_end_of_msgs off
    @ in_names = 0
    @ :col = 0
    @ :i = 0
    @ :line = []
    @ :chan = [$0]
    @ :prefix.op = [@${fg.names_op}]
    @ :prefix.v = [+${fg.names_v}]
    @ :prefix.n = [ ${fg.names_n}]
    @ :w = widest_nick

    # now we work out the number of cols based on the widest nick
    # in the channel.
    # the space available is the scerenwidth - (nickwidth + 1)
    # nickWidth is actually negative, though, so we add it
    @ :space = [79] + nickWidth
    # the +2 is to allow for the @ for ops, and a space between nicks:
    @ :cols = space / (widest_nick + 2)

    # now work out the space between cols, and, if there is room, have up
    # to 3 spaces
    @ :extra = 79 + nickWidth - ((widest_nick + 2) * cols + cols - 1)
    @ extra = 0 - extra / (cols - 1)

    # don't spread the cols out too far:
    if (extra < -2) {
	@ extra = 0 - 2
    }

    # convert extra to $extra spaces:
    if (extra != 0) {
	@ extra = [$([$extra])]
    } {
	@ extra = []
    }

    # a header
    hline ${fg.channelName}${chan}$sc name list:
    @ chan = []
    for (@ i = 0, i < namecount, @ i++) {
	@ stuff = [$igetitem(names_n $i)]
	# stuff is lower-case nick, flag, uppercase nick
	@ theNick = word(2 $stuff)
	@ flag = word(1 $stuff)
	if (col > 0) {
	    @ line #= [$extra]
	}
	@ col++
	if (col == cols) {
	    if (theNick == N) {
		@ line #= [$prefix[$flag]${fg.myNick}${theNick}$nc]
	    } {
		@ line #= [$prefix[$flag]${theNick}$nc]
	    }
	    # @ cols = 4
	    if (chan != []) {
		echo $raf(${fg.channelName}${chan}%n)${ankh.vline} ${line}
	    } {
		echo $raf(${fg.channelName}%n)${ankh.vline} ${line}
	    }
	    @ line = []
	    @ chan = []
	    @ col = 0
	} {
	    @ nlen = w + [1] - [$@theNick]
	    if (nlen < 0) {
		nlen = 0
	    }
	    local nick
	    if (theNick == N) {
		@ nick = [$prefix[$flag]${fg.myNick}${theNick}$nc]
	    } {
		@ nick = [$prefix[$flag]${theNick}$nc]
	    }
	    @ line #= [${nick}$([$nlen] )]
	}
    }
    if ([$line] != []) {
	if (chan != []) {
	    echo $raf(${fg.channelname}${chan}%n)${ankh.vline} ${line}
	} {
	    echo $raf(${fg.channelName}%n)${ankh.vline} ${line}
	}
    }
    for (@ i = namecount, i >= 0, @ i--) {
	@ delitem(names_n $i)
    }
    @ namecount = 0
    echo
    # return 1 to stop BX printing the names too:
    return 1
}

#####################3
# server messages about kills
# display these only if they are not from nickserv.
# You can turn nickserv messages back on with
# /aconf servkills show
ON ^SERVER_NOTICE "* Notice -- Received KILL message for *" {
    if ([$10] == [NickServ]) {
	if ([$13] == [\(Ghosted.]) {
	    if ([$ShowNickServKills] == [show]) {
		@ :nick = [$before(! $8)]
		@ :mask = [$after(! $8)]
		echo $raf(${fg.server}$10%n)  ${fg.server}GHOST${nc} ${fg.nick}${nick}${nc}!${mask} by ${fg.nick}$before(\) $15)${nc} $16-
	    }
	} else {
	    echo $raf(${fg.server}$10%n)  ${fg.server}NSKILL $8 $13-${nc}
	}
    } else {
	echo $raf(${fg.server}$10%n)  ${fg.server}killed $8 $13-${nc}
    }
}

ON ^SERVER_NOTICE "* Global -- from ChanServ: *" {
    echo $raf(${fg.Globals}ChanServ%n): [Global]: $6-
}

ON ^SERVER_NOTICE "* Global -- from NickServ: *" {
    echo $raf(${fg.Globals}NickServ%n): [Global]: $6-
}

ON ^SERVER_NOTICE "* Socks server timeout for *" {
    # hide this
    echo $raf(${fg.Globals}SOCKS%n): $0-
}

#  valinor ***  Global -- from OperServ: CLONES(3): ffg@tsk-34-76.tm.net.my
#  0       1    2      3  4    5         6          7
@ ::clonemask
@ ::Nclones = 0
ON ^SERVER_NOTICE "* Global -- from OperServ: CLONES*" {
    @ ::clonemask = [$7]
    @ ::Nclones = [$after(\( $before(\) $6))]
    echo $raf(${fg.Globals}clones%n)${fg.error}!${nc} $Nclones $clonemask
}

alias clonekill {
    if (::clonemask == []) {
	echo no clones yet! (::clonemask is empty)
    } else {
	@:reason = [$0-]
	if (reason == []) {
	    @ reason = [please do not run clones on this network]
	}
	echo /whokill *!$clonemask :$reason
    }
}

alias clonewarn {
    if (::clonemask == []) {
	echo no clones yet! (::clonemask is empty)
    } else {
	@:reason = [$0-]
	if (reason == []) {
	    @ reason = [please do not run clones on this network]
	}
	notice #$after(@ $clonemask) $reason
    }
}

alias cloneakill {
    if (::clonemask == []) {
	echo no clones yet! (::clonemask is empty)
    } else {
	@::clonereason = [$0-]
	if (clonereason == []) {
	    @::clonereason = [please do not run clones on this network]
	}
	input "akill duration (hours or n) for *!$clonemask ? " {
	    if ([$0] == [n]) {
		echo notdone: /os autokill $0 *!$clonemask $clonereason
	    } else {
		os autokill $0 *!$clonemask $clonereason
	    }
	}

    }
}

alias clonewho {
    who $after(@ $clonemask)
}

alias clonetrigger {
    @ :newnum = [$0]
    if ([$0] == []) {
	@ :newnum = ::Nclones + 5
    }
    # actually os trigger needs a host, not a mask.
    # so if this starts with a * it will fail
    echo os trigger $after(@ $clonemask) $newnum
    os trigger $after(@ $clonemask) $newnum
}

ON ^SERVER_NOTICE "* Global -- from OperServ: *" {
    echo $raf(${fg.Globals}OperServ%n): [Global]: $6-
}


ON ^SERVER_NOTICE "* Global -- from *" {
    if (match(*.${myNet}: $5) > 0) {
	echo $raf(${fg.server}$unnet($sar(/://$5))%n): ${fg.Globals}Global: ${nc}$6-
    } {
	echo $raf(${fg.Globals}$sar(/://$5)%n): ${fg.Globals}Global: $6-${nc}
    }
}

# variables new in 75p3
# p3set -ALTNICK

# SET AINV 0
# SET ALWAYS_SPLIT_BIGGEST OFF
# SET ANNOY_KICK OFF
# SET AOP OFF
# SET APPEND_LOG ON

# p1set AUTOCK OFF

# SET AUTOKICK_ON_VERSION OFF
# SET AUTO_AWAY OFF
# SET AUTO_AWAY_TIME 900
# SET AUTO_LIMIT 0
# SET AUTO_NSLOOKUP OFF
# SET AUTO_RECONNECT ON
# SET AUTO_REJOIN 1
# p1set AUTO_RESPONSE 0
# p3set AUTO_RESPONSE ON
# SET AUTO_RESPONSE_STR Ankh
# SET AUTO_UNBAN 600
# SET AUTO_UNMARK_AWAY OFF
# SET AUTO_WHOWAS OFF
# SET BEEP OFF
# SET BEEP_ALWAYS OFF
# SET BEEP_MAX 3
# SET BEEP_ON_MSG MSGS
# SET BEEP_WHEN_AWAY 0
# SET BITCH OFF
# SET BITCHX_HELP ~/.BitchX/BitchX.help
# SET BLINK_VIDEO ON
# SET BOLD_VIDEO ON
# SET BOT_LOG ON
# SET BOT_LOGFILE tcl.log
# SET BOT_MODE OFF
# SET BOT_PASSWD has no value[0m
# SET BOT_RETURN has no value[0m
# SET BOT_TCL OFF
# SET CDCC_FLOOD_AFTER 3
# SET CDCC_FLOOD_RATE 4
# SET CDCC_PROMPT %GC%gDCC
# SET CDCC_SECURITY 0
# SET CD_DEVICE has no value[0m
# SET CHANGE_NICK_ON_KILL OFF
# SET CHANNEL_NAME_WIDTH 0
# SET CHECK_BEEP_USERS OFF
# SET CLIENT_INFORMATION  Keep it to yourself!
# SET CLOAK 0
# SET CLOCK ON
# SET CLOCK_24HOUR ON
# SET CLOCK_FORMAT has no value[0m
# SET CLONE_CHECK 0
# SET CLONE_COUNT 0
# SET CMDCHARS /
# SET COMMAND_MODE OFF
# SET COMMENT_BREAKAGE OFF
# SET COMPRESS_MODES OFF
# SET CONNECT_TIMEOUT 30
# SET CONTINUED_LINE                 � 
# SET CPU_SAVER_AFTER 0
# SET CPU_SAVER_EVERY 0
# SET CTCP_DELAY 3
# SET CTCP_FLOOD_PROTECTION OFF
#@ SET CTCP_FLOOD_BAN ON
# SET CTCP_FLOOD_BAN OFF
# p3set CTCP_FLOOD_AFTER 3
# p3set CTCP_FLOOD_RATE ON
# SET CTCP_VERBOSE ON
# SET CTOOLZ_DIR ~/.BitchX
# SET DCC_AUTOGET OFF
# SET DCC_AUTORENAME ON
# SET DCC_BAR_TYPE 0
# SET DCC_BLOCK_SIZE 2048
# SET DCC_DLDIR ~
# SET DCC_FAST ON
# SET DCC_GET_LIMIT 0
# SET DCC_MAX_AUTOGET_SIZE 2000000
# SET DCC_QUEUE_LIMIT 10
# SET DCC_SEND_LIMIT 5
# SET DCC_TIMEOUT 600
# SET DCC_ULDIR ~
# SET DEBUG 0
# p3set DEFAULT_FONT -fn vga11x19
# SET DEFAULT_MENU none
# SET DEFAULT_REASON no reason was given
# SET DEOPFLOOD ON
# SET DEOPFLOOD_TIME 30
# SET DEOP_ON_DEOPFLOOD 3
# SET DEOP_ON_KICKFLOOD 3
# SET DISPATCH_UNKNOWN_COMMANDS OFF
# SET DISPLAY ON
# SET DISPLAY_ANSI ON
# SET DISPLAY_PC_CHARACTERS 4
# SET EIGHT_BIT_CHARACTERS ON
# SET EXEC_PROTECTION ON
# SET FAKE_SPLIT_PATS *fuck* *shit* *suck* *dick* *penis* *cunt* *haha* *fake* *split* *hehe* *bogus* *yawn* *leet* *blow* *screw* *dumb* *fbi*
# SET FLOATING_POINT_MATH_VAR OFF
# SET FLOOD_AFTER 4
# SET FLOOD_KICK ON
# SET FLOOD_PROTECTION OFF
# SET FLOOD_RATE 5
# SET FLOOD_USERS 10
# SET FLOOD_WARNING OFF
# SET FTP_GRAB OFF
# SET HACKING 0
# SET HACK_OPS OFF
# p1set HARD_UH_NOTIFY ON
# SET HEBREW_TOGGLE OFF
# SET HELP_PAGER ON
# SET HELP_PATH /usr/local/lib/irc/help
# SET HELP_PROMPT ON
# SET HELP_WINDOW OFF
# SET HIDE_PRIVATE_CHANNELS OFF
# SET HIGHLIGHT_CHAR INVERSE
# SET HIGH_BIT_ESCAPE 0
# SET HISTORY 100
# SET HOLD_MODE OFF
# SET HOLD_MODE_MAX 0
# SET HTTP_GRAB OFF
# SET IDENT_HACK .authlie
# SET IDLE_CHECK 120
# SET IGNORE_TIME 600
# SET INDENT ON
# SET INPUT_ALIASES OFF
# p3set -INPUT_GLOB
# SET INPUT_PROMPT $mkprompt(): 
# SET INPUT_PROTECTION OFF
# SET INSERT_MODE ON
# SET INVERSE_VIDEO ON
# SET JOINFLOOD ON
# SET JOINFLOOD_TIME 50
# SET KICKFLOOD ON
# SET KICKFLOOD_TIME 30
# SET KICK_IF_BANNED ON
# SET KICK_ON_DEOPFLOOD 20
# SET KICK_ON_JOINFLOOD 10
# SET KICK_ON_KICKFLOOD 30
# SET KICK_ON_NICKFLOOD 8
# SET KICK_ON_PUBFLOOD 30
# SET KICK_OPS ON
# SET LAMELIST ON
# p3set LAMEIDENT OFF
# SET LASTLOG 1000
# SET LASTLOG_ANSI ON
# SET LASTLOG_LEVEL ALL
# SET LLOOK OFF
# SET LLOOK_DELAY 120
# SET LOAD_PATH ~/.irc:/usr/local/lib/irc/script:~/.BitchX:.
# SET LOG OFF
# SET LOGFILE IrcLog
# SET MAIL 2
# p3set -MANGLE_INBOUND
# p3set -MANGLE_LOGFILES
# p3set -MANGLE_OUTBOUND
# SET MAX_DEOPS 2
# SET MAX_IDLEKICKS 2
# SET MAX_SERVER_RECONNECT 2
# SET MIRCS ON
# SET MODE_STRIPPER OFF
# SET MSGCOUNT 0
# SET MSGLOG ON
# SET MSGLOG_FILE BitchX.away
# SET MSGLOG_LEVEL MSGS NOTICES SEND_MSG
# SET ND_SPACE_MAX 160
# p3set NAMES_COLUMNS 5
# NAMES_COLUMNS set above
# p3set NEW_SERVER_LASTLOG_LEVEL NONE
# SET NEXT_SERVER_ON_LOCAL_KILL OFF
# p3set NICK_COMPLETION_LEN 2
# SET NICKFLOOD ON
# SET NICKFLOOD_TIME 30
# SET NICK_COMPLETION ON
# SET NICK_COMPLETION_CHAR 
# SET NICK_COMPLETION_TYPE 0
# SET NOTIFY ON
# SET NOTIFY_HANDLER QUIET
# SET NOTIFY_LEVEL ALL
# SET NOTIFY_ON_TERMINATION OFF
# SET NO_CTCP_FLOOD ON
# SET NO_FAIL_DISCONNECT OFF
# SET NUM_BANMODES 4
# SET NUM_KICKS 4
# p3set NUM_KILLS 1
# SET NUM_OF_WHOWAS 4
# SET NUM_OPMODES 3
# SET OPER_MODES swfck
# SET ORIGNICK_TIME 5
# SET OV ON
# SET PAD_CHAR 
# SET PING_TYPE 1
# SET PROTECT_CHANNELS *
# SET PUBFLOOD OFF
# SET PUBFLOOD_TIME 20
# p3set QUEUE_SENDS 0
# p3set RANDOM_LOCAL_PORTS OFF
# p3set RANDOM_SOURCE 0
# SET REALNAME http://www.holoweb.net/~liam/
# SET REASON_TYPE 1
# SET SAVEFILE has no value[0m
# SET SCREEN_OPTIONS has no value[0m
# SET SCRIPT_HELP ~/.BitchX/BitchX.help
# SET SCROLLBACK 512
# SET SCROLLBACK_RATIO 50
# SET SCROLL_LINES 1
# SET SEND_AWAY_MSG ON
# SET SEND_IGNORE_MSG OFF
# p3set SERVER_GROUPS off
# SET SERVER_PROMPT has no value[0m
# SET SHELL /bin/sh
# SET SHELL_FLAGS -c
# SET SHELL_LIMIT 0
# SET SHITLIST ON
# SET SHITLIST_REASON Surplus Lamerz must go!!!!
# SET SHOW_AWAY_ONCE ON
# SET SHOW_CHANNEL_NAMES ON
# SET SHOW_END_OF_MSGS OFF
# SET SHOW_NUMERICS OFF
# SET SHOW_NUMERICS_STR [1;31m�[0m[1;37m�[1;31m�[0m


# SET SHOW_WHO_HOPCOUNT OFF
# SET SOCKS_HOST has no value[0m
# SET SOCKS_PORT 1080


# SET SUPPRESS_SERVER_MOTD ON
# SET SWATCH COLLIDE,KILLS,MISMATCH,HACK,IDENTD,FAKES,UNAUTHS,CLIENTS,TRAFFIC,REHASH,KLINE,BOTS,OPER,SQUIT,SERVER,CONNECT,FLOOD,USER,STATS,NICK,ACTIVEK,CRAP
# SET TAB ON
# SET TAB_MAX 8
# SET TRANSLATION has no value[0m
# SET UNDERLINE_VIDEO ON
# SET USERLIST ON
# SET USERMODE +iw
# SET USER_FLAG_OPS has no value[0m
# SET USER_FLAG_PROT has no value[0m
# SET USER_INFORMATION 
# SET WINDOW_QUIET OFF
# SET WORD_BREAK ,; 	
# SET XTERM has no value[0m
# SET XTERM_OPTIONS -bg black -fg white -fn vga11x19
# SET XTERM_TITLE OFF
# SET _CDCC_CLOSE_IDLE_SENDS_TIME 55
# SET _CDCC_MINSPEED_TIME 0
# SET _CDCC_PACKS_OFFERED 0

####################
# Services
# Identifying to services requires handling a password.
# You can have a separate password for each nick.
#
# TODO: Work out when NickServ wants us to identify
#
# when nickserv asks us for a password, we look to see if we know it.
# if so, we identify automatically.
# if nickserv says password incorrect, 
# we clear out the password and warn the user to identify.
alias ns.wantident {
    if ([$nspass[$N]] != "") {
	ns.id $nspass[$N]
    } {
        echo $raf(${fg.error}IDENTIFY%n): ${fg.error}You must identify to NickServ.%n
    }
}

bind  parse_command aichannelchanger
alias aichannelchanger {
    parsekey switch_channels
    xecho -c $raf(" ")  ${fg.channelname}$C${nc}
}

# /^FSET -FORMAT_SEND_NOTICE
# /^FSET FORMAT_SEND_NOTICE \$addwin(notice $1)\$raf(->-${fg.notice}$1%n)- \$3-
alias HiddenMessage {
    hline %ysending $1 to $0
    on ^WINDOW "*" {
    }
   msg $0 $1-
   ^on ^window -"*"
}

alias nsid {
    @ nspass[$encode($N)] = [$0]
    HiddenMessage NickServ IDENTIFY $0-
}

alias id {
    if ([$0] != []) {
	@ nspass[$encode($N)] = [$0]
    }
    if ([$nspass[$encode($N)]] == [] || [$0] == [-]) {
	input -noecho "NickServ password: " nsid \$*
    } {
	nsid $nspass[$encode($N)]
    }
}

####
# lusers
# :localhost 251 james :There are 1 users and 1 invisible on 1 servers
# :localhost 255 james :I have 2 clients and 0 servers
# :localhost NOTICE james :Highest connection count: 2 (2 clients)
on ^251 "*" {
    echo
    echo $raf($fg[server]server%n): $0
    echo $raf(users): visible: $3 invisible $6\; total ${[$3] + [$6]}
    echo $raf(servers): $9  (use /links for details)
}
on ^255 "*" {
    echo $raf(local clients): $3  (not including servers)
    echo $raf(server links): $6

    on ^SERVER_NOTICE "* Highest connection count: *" {
        echo $raf(maxiumum): $5- since last restart
	echo
	on ^SERVER_NOTICE -"* Highest connection count: *"
    }
}

# valinor.sorcery.net *** Notice -- Kill line active for [host]
# 0                   1   2      3  4
on ^SERVER_NOTICE "* Kill line active *" {
    echo $raf($fg[server]$unnet($0)%n)  $4-
}

on ^SERVER_NOTICE "* Flood -- *" {
    echo $raf($fg[server]$unnet($0)%n)  FLOOD: $0-
}

## ison
on ^303 "*" {
    if ([$0] == []) {
	echo $raf(${fg.server}Not online%n): users not online.
    } {
	echo $raf(${fg.server}Currently online%n): $0-
    }
}

####################
# file reading
alias copyfile {
    @ :filename = [$0]
    @ :fd = open($filename R)
    if ([$fd] == []) {
        xecho -current $raf(${fg.error}copyfile%n): could not open "$filename"
	return
    }
    @ finished = 0
    while (finished == 0) {
        @ text = read($fd)
	if (text == []) {
	    @ finished = 1
	} {
	    xecho -current -nolog -- $text
	}
    }
    @ close($fd)
}

####################
# stats l
# sender 211 target linknick|server sendq smsgs sbytes rmsgs rbytes timeopenI# 
# 0      1   2       3              4     5     6      7     8      9
on ^raw_irc "% 211 *" {
    if ([$5] == [SendBytes]) {
	# reset the list of ports:
	@ :p
	foreach portusers p {
	    @ portusers[$p] = 0
	}
	# arrange to print a summary at the end
	set show_end_of_msgs on
	on ^219 "*" /end_stats_l

	# print a heading
	xecho -c
	xecho -c xecho -c $raf(${fg.server}$unnet($0)%n): stats L (links)
	hline
    } else {
	# valinor.sorcery.net[@0.0.0.0.6667]
	# valinor.sorcery.net[@216.122.249.75.9000]
	# Ankh[@64.230.28.113.65524]

	@ :client = before([ $3)
	@ :ip = after(@ $3)
	@ ip = before(] $ip)
	@ :port = after(4 . $ip)
	@ ip = before(4 . $ip)
	if (ip == [0.0.0.0]) {
	    @ ip = []
	}
	@ :duration = [$9]
	# @ duration = duration * 60
	if (before(. $client) == []) {
	    # a user
	    @ client = [${fg.nick}${client}${nc}]
	    # remember this port
	    @ :p
	    @ p = portusers[$port]
	    if (p == []) {
		@ p = 0
	    }
	    @ p++
	    @ portusers[$port] = p
	} else {
	    @ client = [${fg.server}$unnet($client)${nc}]
	}

	@ :sendq = [$4]
	if ([$4] == [0]) {
	    @ sendq = []
	} else {
	    @ sendq = [ $4 sendq\;]
	}

	if ([$ip] != [] || $5 > 0 || $7 > 0) {
	    xecho -c $raf($client):$sendq sent msgs $5/$6 bytes, recv'd $7/$8
	    xecho -c $raf($ip): port $port, connected $tdiff($duration)
	} else {
	    xecho -c $raf($client): port $port, connected $tdiff($duration)
	}
    }
}

alias end_stats_l {
    on ^219 "*"
    set show_end_of_msgs off
    @ :p
    foreach portusers p {
	if (portusers[$p] > 0) {
	    @ :nusers = portusers[$p]
	    xecho -c $raf(${fg.help}port $p%n): user count: $nusers
	}
	@ portusers[$p] = 0
    }
    hline
    xecho -c
}

####################
# handle incoming channel notices
#
on ^RAW_IRC "* NOTICE @#*" {
    @ :chan = mid(1 1000 $2)
    @ :i = 0

    @ :from = before(! $0)
    @ :text = mid(1 1000 $3-)

    if ($chanwin($chan) != -1) {
	xecho -window $chanwin($chan) $raf(-${fg.notice}${from}%n)- ${fg.channelName}[$2]${nc} ${fg.notice}${text}${nc}
    } {
	echo -$raf(${fg.notice}${from}%n)- ${fg.channelName}[$2]${nc} ${fg.notice}${text}${nc}
    }
}

# see /ehelp 5 on, for explanation of ambiguous mode with the "?":
# returning 1 means default action is not done
alias matchkill {
    @ aiakillmask = [$0]
    ^on ^NOTICE "OperServ *" {
	if ([$1] == [End]) {
	    # delete the action
	    on -NOTICE "OperServ *"
	    # echo to show we did it
	    hline
	} elsif (match($3 $aiakillmask)) {
	    @ :dateplaced = [$1]
	    @ :duration = after(\[ $2)
	    echo $raf(matchkill)  $dateplaced $duration $3 $4-
	}
    }
    os autokill
}

# ignore channel sync messages
on ^channel_synch "*" {return}

# URL grabs

# args are:
# number count from from-user@host channel text more text here
# 0      1     2    3              4       5
^on ^urlgrab "*" {
    url_catch $*
    return 1
}

# echo long line with no contuation
alias longecho {
    ^set -CONTINUED_LINE
    echo ${fg.url}$0-${fg.nc}
    ankh.setline $ankh.vline
}

alias url_catch {
    @ :url = url_http($5-)
    if (url != []) {
	longecho URL $url
    } else {
	@ url = url_ftp($5-)
	if (url != []) {
	    longecho URL $url
	}
    }

    if (url != []) {
	@ saved_urls[$0] = url ## [ (] ## [$1/$4] ## [)]
    }
}

alias url_ftp {
    @ :input = [$0-]

    @ :ftp = strstr(ftp $input)
    if (ftp == []) {
	return
    }
    @ :url = word(0 $ftp)

    if (url == []) {
	return
    }
    return $url
}

alias url_http {
    @ :input = [$0-]

    @ :http = strstr(http $input)
    if (http == []) {
	return
    }
    @ :url = word(0 $http)

    if (url == []) {
	return
    }
    return $url
}


###
# URLs - not ready yet
#
# @ url[0] = [http://www.valinor.sorcery.net/ -- Valinor IRC Server]
# @ url[1] = [http://www.valinor.sorcery.net/~liam/bx -- Ankh.bx home page]
# 
# @ wwwbrowser = [netscape -remote]
# on ^URLGRAB "*" {
#     @ url[$0] = [$4-]
#     echo n is $n, $(n) and $($n)
#     echo URL $0 saved, /url list to see, /urlshow to run $wwwbrowser
# }
# 
# alias urlshow {
#     do echo $wwwmbrowser "$(url.$0)"
# }

####################
# startup stuff
# load default colours
loadTheme default silent

do copyfile $ANKHDIR/splash.ansi
echo
aload conf
hline ${fg.Help}Loaded ankh.bx script, theme: $tvar.name%n
